Hall of Famer Posted August 1, 2011 Share Posted August 1, 2011 Well I am retrieving database properties from two tables(items and inventory), but I do not know how to do this easily so I tried the method below, in which I use mysql_fetch_array($result) for properties of table prefix_inventory and mysql_fetch_array($result2) for properties of table prefix_items. It does not work at all though, only the first mysql_fetch_array works, the second one will not retrieve any database information for me. What have I done wrong, is there a way to fix this? $result = mysql_query("SELECT * FROM {$prefix}inventory WHERE owner ='{$loggedinname}'"); while($row = mysql_fetch_array($result)){ // First we need to retrieve item properties. $result2 = mysql_query("SELECT * FROM {$prefix}items WHERE itemname ='{$row['itemname']}'"); $items = mysql_fetch_array($result2); $article_content .= "<tr> <td><img src='{$items['imageurl']}'></td> <td>{$row['category']}</td> <td>{$row['itemname']}</td> <td>{$items['description']}</td> <td>{$row['quantity']}</td>"; // There are still lines below, but wont make a difference even if I post them Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/ Share on other sites More sharing options...
Drummin Posted August 1, 2011 Share Posted August 1, 2011 Try WHERE itemname ='{$row[itemname]}' Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/#findComment-1250096 Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 $result2 = mysql_query("SELECT * FROM {$prefix}items WHERE itemname ='{$row['itemname']}'"); why curly bracket ? Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/#findComment-1250102 Share on other sites More sharing options...
Drummin Posted August 1, 2011 Share Posted August 1, 2011 I don't use them as posted but some coders do. Just sticking with the format he posted. Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/#findComment-1250103 Share on other sites More sharing options...
voip03 Posted August 1, 2011 Share Posted August 1, 2011 I thought new php syntax to put '{' Hall of Famer remove the {} and try Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/#findComment-1250105 Share on other sites More sharing options...
PFMaBiSmAd Posted August 1, 2011 Share Posted August 1, 2011 The {} are needed around associative array variables inside of strings so that you can keep the quotes around the associative key name without breaking the string syntax. You can also use them around any php variable inside of a string for those cases where you need to tell php where variables start and end. See the Complex (curly) syntax section at this link - http://cn.php.net/manual/en/language.types.string.php Quote Link to comment https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/#findComment-1250177 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.