Jump to content

Mysql_fetch_array problem...


Hall of Famer

Recommended Posts

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

 

Link to comment
https://forums.phpfreaks.com/topic/243451-mysql_fetch_array-problem/
Share on other sites

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.