davey_b_ Posted April 25, 2008 Share Posted April 25, 2008 Why am I getting this??? Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /var/www/.../vieworder.php on line 130 <?php $sql=" SELECT o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price FROM ".$tableprefix."orders o,".$tableprefix."currency_master cm INNER JOIN ".$tableprefix."users u ON o.user_id = u.user_id INNER JOIN ".$tableprefix."order_details od ON o.order_id = od.order_id WHERE o.order_id = ".GetSQLValueString($orderid,"text")." AND o.vorder_currency = cm.vcurrency_code AND o.user_id = ".$_SESSION["sess_userid"]. $qryopt . " ORDER BY o.order_date DESC "; $result = mysql_query($sql); if(mysql_num_rows($result) !=0) { $prow = mysql_fetch_array($result); $ordernumber = $prow["order_id"]; $username = $prow["user_name"]; $ordertotal = $prow["order_total_price"]; $orderdate = $prow["order_date"]; $orderdate = dateFormat($orderdate,"Y-m-d","d-M-Y"); $userid = $prow["user_id"]; $exchange_price = $prow["nexchange_price"]; } else { $order_flag = 1; } Quote Link to comment Share on other sites More sharing options...
aschk Posted April 25, 2008 Share Posted April 25, 2008 $result is not a valid MySQL result. Simple really i.e. your SQL statement failed, because MySQL didn't return a resultset... Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 25, 2008 Author Share Posted April 25, 2008 Why am i not getting a result when there is information in the database for it to retrieve? This problem has really confused me! Quote Link to comment Share on other sites More sharing options...
aschk Posted April 25, 2008 Share Posted April 25, 2008 Your SQL statement is wrong, it is failing... Do the following to get the part of the SQL that is wrong. echo mysql_error(); Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 25, 2008 Author Share Posted April 25, 2008 where should I put that - sorry I'm a bit new to this :-\ Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2008 Share Posted April 25, 2008 where should I put that - sorry I'm a bit new to this :-\ Right after issuing the query. Seeing the query too, with an echo, would help. Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 25, 2008 Author Share Posted April 25, 2008 Being a bit of a n00b! Query: SELECT o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price FROM tug_orders o,tug_currency_master cm INNER JOIN tug_users u ON o.user_id = u.user_id INNER JOIN tug_order_details od ON o.order_id = od.order_id WHERE o.order_id = '5' AND o.vorder_currency = cm.vcurrency_code AND o.user_id = 1 ORDER BY o.order_date DESC Error: (1054) Unknown column 'o.user_id' in 'on clause' Quote Link to comment Share on other sites More sharing options...
fenway Posted April 25, 2008 Share Posted April 25, 2008 Tsk, tsk... don't mix comma and JOIN! Let me guess, you're using MySQL 5? This will work, but it's band-aid: SELECT o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price FROM ( tug_orders o,tug_currency_master cm ) INNER JOIN tug_users u ON o.user_id = u.user_id INNER JOIN tug_order_details od ON o.order_id = od.order_id WHERE o.order_id = '5' AND o.vorder_currency = cm.vcurrency_code AND o.user_id = 1 ORDER BY o.order_date DESC This is much better: SELECT o.*, u.user_name, u.email, od.artist_id,cm.nexchange_price FROM tug_orders o INNER JOIN tug_currency_master cm ON ( o.vorder_currency = cm.vcurrency_code ) INNER JOIN tug_users u ON ( o.user_id = u.user_id ) INNER JOIN tug_order_details od ON ( o.order_id = od.order_id ) WHERE o.order_id = '5' AND o.user_id = 1 ORDER BY o.order_date DESC Quote Link to comment Share on other sites More sharing options...
davey_b_ Posted April 25, 2008 Author Share Posted April 25, 2008 Yes MySQL 5.0.22. All i can say is wow, thanks for the lesson. Put the new code in and it worked like a charm. Guess they don't give those many stars to just anyone Thanks again. Quote Link to comment 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.