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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.