biji buji
biji buji

Reputation: 465

can not access mySql result in php

I have this mySQL query:

Select MIN(A.product_id  + 1)
From   Tabel A Left Join Tabel B
On A.product_id = B.product_id - 1
Where  B.product_id Is NULL  

I run it on phpMyAdmin and this is the result:

phpMyAdmin screenshot

It returns the correct value (1803020005) but under the field 'MIN(a.product_id + 1)'.

How can I use it in php?

I use this but does not work:

$result = mysql_query ($select, $con);
$row = mysql_fetch_assoc($result);  

this is the result of $result = mysql_query ($select, $con); :

Resource id #6

and this is the result of $row = mysql_fetch_assoc($result); :

Array

Upvotes: 3

Views: 136

Answers (3)

Justin
Justin

Reputation: 2161

Your query is completely wrong....

On A.product_id = B.product_id -1 WHERE b.product_id IS NULL

Is telling MySQL that A.product_id must be the same as b.product_id subtracted by 1 as long as b.product_id is empty

Now, I think that you're looking for WHERE B.product_id IS NOT NULL and all your woes will be repaired.

Also, read up on mysqli and PDO as the mysql extensions (ie: mysql_query) are not maintained and contain a lot of security issues.. PDO takes some getting used to, mysqli you can switch to relatively easy without much hassle..

Upvotes: 0

Joe Majewski
Joe Majewski

Reputation: 1641

You want to SELECT MIN(a.product_id +1) AS min and then get it under $row['min'];

Upvotes: 2

Trey
Trey

Reputation: 5520

Select MIN(A.product_id  + 1) AS product_id
From   Tabel A Left Join Tabel B
On A.product_id = B.product_id - 1
Where  B.product_id Is NULL  

try telling it what you want the field to be returned as

Upvotes: 1

Related Questions