FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Warning: mysql_fetch_array():Help me........





bartdou
A database named "mydata" of a shop, 3 ralated tables of it:
customers:CustID Custname Email Address
products:ProductID ProductName Category Price
orders:OrderID CustID ProductID OrderDate SendDate Qty

the following codes show out a certain customer's order list.
Code:
<?php
$cn=mysql_connect('localhost','root','123456')
    or die("Fail to connect!");
$strsql="select OrderID,OrderDate,ProductName,Category,Qty,Price ".
        "from customers,orders,products ".
        "where customers.CustName='Marry' ".
        "and customers.CustID=orders.CustID ".
        "and orders.ProductID=products.ProductID";
         
$result=mysql_db_query("mydata",$strsql,$cn);
echo"Marry ordered the following products:<br>";
echo "<table border=1>";
echo"<tr><td><b>OrderNumber</b></td><td><b>OrderDate</b></td><td><b>ProductName</b></td><td><b>Category</b></td><td><b>Number</b></td><td><b>Price</b></td></tr>";
while($arr=mysql_fetch_array($result)){     [color=darkred]//here is line 39[/color]
print("<tr><td>$arr[OrderID]</td><td>$arr[OrderDate]</td><td>$arr[ProductName]</td><td>$arr[Category]</td><td>$arr[Qty]</td><td>$arr[Price]</td></tr>");
}
echo"</table>";
?>



Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\APMServ5.1.2\www\htdocs\customer\show.php on line 39


I think the problem occured in the select sentence, we just select out OrderID,OrderDate,ProductName,Category,Qty,Price from the 3 tables,but not CustName,customers.CustID,orders.CustID,orders.ProductID,products.ProductID, can we use them in the select limits?

I'm an English learner, excuse me for some ambiguous expression.
izcool
This might work, although I haven't tested it myself.

Code:
<?php
$cn = mysql_connect("localhost","root","123456") or exit("MySQL Error :  " . mysql_error()); 
$result = mysql_query("SELECT OrderID,OrderDate,ProductName,Category,Qty,Price FROM customers,orders,products WHERE customers.CustName='Marry' AND customers.CustID=orders.CustID AND orders.ProductID=products.ProductID",$cn) or exit("MySQL Error :  " . mysql_error());
echo"Marry ordered the following products:<br>
<table border=1>
<tr><td><b>OrderNumber</b></td><td><b>OrderDate</b></td><td><b>ProductName</b></td><td><b>Category</b></td><td><b>Number</b></td><td><b>Price</b></td></tr>";
while($arr = mysql_fetch_array($result)){
echo"<tr><td>$arr[OrderID]</td><td>$arr[OrderDate]</td><td>$arr[ProductName]</td><td>$arr[Category]</td><td>$arr[Qty]</td><td>$arr[Price]</td></tr>";
}
echo"</table>";
?>


Good luck.

- Mike.
yy1124
bartdou wrote:
A database named "mydata" of a shop, 3 ralated tables of it:
customers:CustID Custname Email Address
products:ProductID ProductName Category Price
orders:OrderID CustID ProductID OrderDate SendDate Qty

the following codes show out a certain customer's order list.
Code:
<?php
$cn=mysql_connect('localhost','root','123456')
    or die("Fail to connect!");
$strsql="select OrderID,OrderDate,ProductName,Category,Qty,Price ".
        "from customers,orders,products ".
        "where customers.CustName='Marry' ".
        "and customers.CustID=orders.CustID ".
        "and orders.ProductID=products.ProductID";
         
$result=mysql_db_query("mydata",$strsql,$cn);
echo"Marry ordered the following products:<br>";
echo "<table border=1>";
echo"<tr><td><b>OrderNumber</b></td><td><b>OrderDate</b></td><td><b>ProductName</b></td><td><b>Category</b></td><td><b>Number</b></td><td><b>Price</b></td></tr>";
while($arr=mysql_fetch_array($result)){     [color=darkred]//here is line 39[/color]
print("<tr><td>$arr[OrderID]</td><td>$arr[OrderDate]</td><td>$arr[ProductName]</td><td>$arr[Category]</td><td>$arr[Qty]</td><td>$arr[Price]</td></tr>");
}
echo"</table>";
?>



Quote:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in D:\APMServ5.1.2\www\htdocs\customer\show.php on line 39


I think the problem occured in the select sentence, we just select out OrderID,OrderDate,ProductName,Category,Qty,Price from the 3 tables,but not CustName,customers.CustID,orders.CustID,orders.ProductID,products.ProductID, can we use them in the select limits?

I'm an English learner, excuse me for some ambiguous expression.


Did you tried it?
I mean, using CustName,customers.CustID,orders.CustID,orders.ProductID,products.ProductID
You can use these in select statement, and to me, you should use it...
bartdou
Thank you, it works.
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.