Johnny G Junior's NoteBook Treasures: August 2011

Wednesday, August 10, 2011

where are you spaces? PHP / MYSQL

so you have an entry in your MYSQL database that has a space.

for example in your field named ProjectName you have the entry "Fire Cards".
when it gets returned into PHP, you may experience this:

result: Fire

you see that the entry is in mysql but for some reason its stops at the space. WHAT IS THE DEAL WITH THAT.. don't worry, here is your fix.

rawurlencode(); 

//  keeps the spaces in and turns it to %20

urldecode(); 

//  converts %20 to an actual space.


you used this like this. rawurlencode(THIS ITEM);

Heres how it works. if i want to find the result of ProjectName it would look like this.
 While($row = mysql_fetch_array($result)){  
   
 $projectName = rawurlencode($row['ProjectName']);  
   
 }  
   
 echo $projectName;  
   
 the result: Fire%20Cards  
   
 }  


Now to get it to display the space as a "space" add urldecode after you get it out of MYSQL with the rawurlencode.

 While($row = mysql_fetch_array($result)){  
   
 $projectName = rawurlencode($row['ProjectName']);  
   
 $projectName = urldecode($projectName);  
   
 }  
   
 echo $projectName;  
   
   
   
 the result: Fire Cards  
   
 }  


hope this saved your world from blowing up. Im out.