zpupster Posted April 9, 2017 Share Posted April 9, 2017 hello support, I am trying to update an old script. mysql sql statement that works is: $result = mysql_query( "SELECT products.products_id AS id, products_description.products_name AS name, products.products_quantity AS quantity, products.products_weight AS weight, products.products_price AS price FROM products, products_description WHERE products.products_id=products_description.products_id;") or die(mysql_error()); while($row = mysql_fetch_array( $result )) { mysqli statement that i can not get to work is: $sql = "SELECT products_id, products_description.products_name, products_quantity, products_weight, products_price FROM products INNER JOIN products_description on products.products_id = products_description.products_id"; $result = mysqli_query($con, $sql); if(mysqli_num_rows($result)>0){ while(null !== ($row = mysqli_fetch_assoc($result))) { the error i receive is: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in index.php on line 19 the my sqli code worked but not when i add the products_description.products_name to the query. TY Quote Link to comment Share on other sites More sharing options...
NigelRel3 Posted April 9, 2017 Share Posted April 9, 2017 Isn't product_id on two tables in your statement - should you precede it with the table name. Couple of things... Try and space out your SQL statements to make them easier to read, so select blah from blah where blah = bllah Also when you have long table names, use table aliases... select b.blah from blah_blah_blab b where b.blah = bllah makes it much easier to read (IMHO) Quote Link to comment Share on other sites More sharing options...
ginerjm Posted April 9, 2017 Share Posted April 9, 2017 And STOP using the MySQL functions. Switch to the mysqlI ones or better yet, use PDO Quote Link to comment Share on other sites More sharing options...
zpupster Posted April 9, 2017 Author Share Posted April 9, 2017 here is a solution that worked for me. $sql = "SELECT p.products_id, pd.products_name, p.products_quantity, p.products_weight, p.products_price FROM products p INNER JOIN products_description pd on p.products_id = pd.products_id"; I apologize my code is not neat , something i can work on. to ginerjm, that is exactly what i stated that i was doing updating from mysql to to mysqli, i than can learn how to do this in PDO. maybe you can help me with that. TY Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted April 9, 2017 Share Posted April 9, 2017 Forget about mysqli. It's complicated and only makes sense for people who thoroughly study the manual before they write any code. You clearly don't fall into that category, so you should use the much simpler PDO extension instead. Quote Link to comment Share on other sites More sharing options...
emptry Posted April 9, 2017 Share Posted April 9, 2017 Jacques1: Sorry my friend, i do not agree with you. I'm using mysqli, with great succes, and i dont find it complicated, how come you think that ? Quote Link to comment Share on other sites More sharing options...
benanamen Posted April 9, 2017 Share Posted April 9, 2017 Jacques1: Sorry my friend, i do not agree with you. I'm using mysqli, with great succes, and i dont find it complicated, how come you think that ? Show us one the same bit of code using a WHERE clause. That will tell us if you know what you're doing. 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.