Variable not working, going crazy!!

Hey guys, php virgin here!
Basically Im trying to implement CKeditor with my database however Im trying to use a variable inside mysql_query however it doesn’t seem to work. It does work when I change the variable to a number but not otherwise. The code is:
[php] // Get data from the database
$query = mysql_query(“SELECT proid FROM fck_data WHERE id = 1”);
$proid = mysql_fetch_array($query);

$result = mysql_query(“SELECT fulldescr FROM xcart_products WHERE productid = '”.$proid."’");
$fulldescr = mysql_fetch_array($result);[/php]

Ive tried echo which says ‘Array’ for some reason and Ive tried putting in the variable without any quotes and still no hope.
Any help would be greatly appreciated
Regards

I take it by $fulldescr you’re referring to some kind of text or string. When you use mysql_fetch_array, it returns an array - as the function’s name suggests. Even though you’re only requesting one item, an array will still be given. You should change:

[php]$fulldescr = mysql_fetch_array($result);[/php]

To:

[php]$raw_result = mysql_fetch_array($result);
$fulldescr = $raw_result[‘fulldescr’];[/php]

Thank you so much for the prompt reply, however after trying that it didnt seem to work. I have diagnosed the problem to being the variable since it does work if it is changed to a number which corresponds to a product id on the database. Any more help would be greatly appreciated

I didn’t realise but you have a similar issue above the latter one:

[php]$proid = mysql_fetch_array($query);[/php]

Needs to be:

[php]$raw_result = mysql_fetch_array($query);
$proid = $raw_result[‘proid’];[/php]

That was the problem! I changed the first one but kept the second as was and it fixed it. You are an absolute legend dude thank you soo much!! ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service