Jump to content

array from MySQL question


Recommended Posts

Hi,

 

I have an array that I've set up as a JSON feed API. The array pulls data from a MySQL query, one of the fields in the query ('description') contains text with escape characters.

 

I'm just wondering how I change either the query to remove the escape characters (ie can you strip escape chars in MYSQL?) - or change the array to strip the escape chars??

 

//Run query
$result = mysql_query('
SELECT 
DATE_FORMAT(gl_date,"%d-%m-%Y")as "date",
gl_venue as "venue",
gl_city as "city",
gl_postcode as "postcode",
gl_text as "description",
concat(DAYOFMONTH(gl_date), MONTHNAME(gl_date),".png") AS "imageName"
FROM tg_gig_list 
where
gl_date >= curdate()
and gl_publish = 1
order by gl_date

');



$array = array();
$array['gigs'] = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{ 
  $array['gigs'][] = $row;
}
$output = json_encode($array);

}

 

Link to comment
Share on other sites

If you have escape characters actually inserted into the database along the data, then you have a problem when the data is being inserted. It is somehow being double-escaped, either by having magic_quotes_gpc on and not handling it with stripslashes, or you're using more than one escaping routine. The escape characters should not end up in the database.

Link to comment
Share on other sites

If you have escape characters actually inserted into the database along the data, then you have a problem when the data is being inserted. It is somehow being double-escaped, either by having magic_quotes_gpc on and not handling it with stripslashes, or you're using more than one escaping routine. The escape characters should not end up in the database.

 

just having a look at my data,  I'm using mysql_real_escape_string to put the text into the database, the only characters that are coming out of (stored in) the database are "\r\n" for line breaks, these get processed fine in HTML but come through as they are when I take them into an Xcode textarea.

 

Thinking about this I could probably leave them where they are and find/replace them in a method in Xcode - sound like a question for the iOS dev forum!

 

Thanks anyway everyone - for helping me to get to that conclusion!

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.