I was wondering if you guys can help me with this! I'm trying to display data on the items_Deltails.php page from classifieds1.php page using $_GET. I'm able display all data from items table without any problem, however when i try to display the field pix from the images table it comes up with this message "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\web\htdocs\Item_Details.php on line 35".

I've two different tables one clled items (itemID, categoryID, item_Description, itemName, price, contactNAme, phone and email) and the other one called images (itemID, categoryID and pix).
I'm sure the there is something from with the mysql command "SELECT * FROM" in item_Details.php

Here is the code for classifieds1.php

echo "<h1>List of all items</h1>";
//database info in misc.inc
$table = "items";
$db = 0;
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

$query1 = "SELECT * FROM items WHERE categoryID='3'";
$result = mysql_query($query1);
//let's get the number of rows in our result so we can use it in a for loop
$numofrows = mysql_num_rows($result);

echo"<table id=mytable cellspacing=0 summary=Items from almacen database>
<caption>Books, CDs and DVDs: </caption>";
echo "<TR bgcolor=\"lightblue\"><TH>Item Name</TH><TH>Price</TH><TH>Posted On</TH></TR>\n"; 
for($i = 0; $i < $numofrows; $i++) {
$row = mysql_fetch_array($result); //get a row from our result set
if($i % 2) { //this means if there is a remainder
echo "<TR bgcolor=\"#F5FAFA\">\n";
} else { //if there isn't a remainder we will do the else
echo "<TR bgcolor=\"#FFFFFF\">\n";
echo "<TD><a href='http://localhost/item_Details.php?itemID=$id' target = '_blank'>{$row['itemName']}</a></TD>
<TD>&pound;".number_format ($row['price'],2)."</TD><TD>".$row['submitDate']."</TD>\n";
echo "</TR>\n";
echo "</table><br/>";

And here is the code for items_Details

//database info in misc.inc
//Get item ID
$id = $_GET["itemID"];
$db = 0;
//Connect to database
$db = mysql_connect($db_host . ":" . $db_port, $db_user, $db_pwd);
if ($db == 0) {die("Cannot connect, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};

mysql_query("USE " . $db_db);
if (mysql_errno() != 0) {die("Cannot USE database, Error <b>" . mysql_errno() . "</b>: " . mysql_error());};
//fetch data from database
$query1 = "SELECT * FROM images, items WHERE itemID=$id";
$result = mysql_query($query1);
while ($row = mysql_fetch_array ($result))
echo"<td colspan='2'>
  <h2 style='font-size: large;'> ".$row['itemName']."</h2><br />
    <span id=''></span>
<img border='0' align='right' src='../images/{$row['pix']} alt='item Image' style='margin-left: 5px;'> '<br />
         <b>Price: </b>&pound;" .number_format ($row['price'],2). "<br />
         <b>Posted On: </b>" .$row['submitDate']. "<br />\n
<b>Description: </b><p>" .$row['item_Description']. "<p><br />
 <div ;='' style=clear: both;>
  <h4 style='font-size: medium;'>Contact details:</h4>
<b>Name: </b>" .$row['contactName']. "<br />
<b>E-mail: </b>".$row['email']." <br /><br />  
echo "</table><br/>";

Thank you very much.

Edited by Rizzuti: font needed to be edit

8 Years
Discussion Span
Last Post by Rizzuti

line 14

$query1 = "SELECT * FROM images, items WHERE itemID=$id";

is incorrect.

use this sql

SELECT item.itemID, item.categoryID, item.item_Description, item.itemname, item.price, item.contactNAme, ite.phone, item.email, images.itemID, images.pix
FROM item
FULL JOIN images
ON item.itemID=images.itemID
ORDER BY item.itemID

this will join both tables together.
You don't need to write it like this, but this way you can delete the ones you don't want to select.

EDIT: you still need to add your WHERE statement to this

Hope this helps :)

Edited by metalix: n/a


or first try:
$query1 = "SELECT * FROM images WHERE itemID='$id'";

Don't forget your single quotes ;)

echo "SELECT * FROM images, items WHERE itemID=$id"; exit;

echo select query and see out output .

i think problem is selecting two tables. try like this

$query1 = "SELECT * FROM images, items WHERE (images.itemID=$id && items.itemID=$id)"; exit;

Edited by raju_boini525: n/a


Excellent. it works like this:
$query1 = "SELECT * FROM images, items WHERE (images.itemID=$id && items.itemID=$id)";
without the exit;

Thank you very much you both guys!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.