Page 1 of 1
mysql_fetch_array() when querying from more than 1 table
Posted: Thu Jun 10, 2004 8:13 am
by anjanesh
Hello
I have this
Code: Select all
$res=mysql_query("SELECT a.InvStatus,b.CustID,b.IncrCredit FROM CartMaster a,Customer b WHERE a.CustID=b.CustID");
$row=mysql_fetch_row($res);
$row['IncrCredit'] won't work but
$row[2] will. Or is there another method ?
$RewardPts=$row['IncrCredit'];
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in xxx.......xxx\xxx.php on line 179
Thanks
Posted: Thu Jun 10, 2004 8:20 am
by lostboy
use column alias to id the column, then use the alias name
Code: Select all
$res=mysql_query("SELECT a.InvStatus as status,b.CustID as ID, b.IncrCredit as Credit FROM CartMaster a,Customer b WHERE a.CustID=b.CustID");
...
$customer = $rows['ID'];
$credit = $rows['Credit'];
....
Posted: Thu Jun 10, 2004 8:30 am
by anjanesh
Now it doesn't give a warning. It gives a notice. Is there anything I have to change in php.ini ?
Notice: Undefined index: IncrCredit in c:\program files\apache group\apache\htdocs\shoppingportal\admin\invoicestatus.php on line 180
Posted: Thu Jun 10, 2004 8:32 am
by anjanesh
Sorry. That had to be changed to mysql_fetch_array()
Posted: Thu Jun 10, 2004 8:35 am
by anjanesh
I am not getting a warning for this :
Code: Select all
$sql="
SELECT (a.PresentCredit*b.Qty)
FROM Product a,CartDetail b
WHERE a.PID=b.PID AND a.CartID='".$_POST['InvNo'][$i]."'"
$res=mysql_query($sql);
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\apache\htdocs\shoppingportal\admin\invoicestatus.php on line 182
And in phpmyadmin it doesn't show any error but at the same time it does not display the multiplication result of these 2 values
Posted: Thu Jun 10, 2004 9:47 am
by pickle
Try making your mysql_query line into this:
Code: Select all
$res=mysql_query($sql) or die(mysql_error());
just to see if you get an error when you query.
Posted: Thu Jun 10, 2004 9:59 am
by feyd
just to clarify mysql_fetch_row()... it only returns index offset built queries.. so $blah['somefield'] will always fire a warning.