Jump to content

mysqli sql trouble


zpupster

Recommended Posts

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

 

 

 

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.