3

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

8
  • 1
    Why don't you print_r your $row and see what it contains (and post it)? Also, you should be using MySQLi or PDO, as php_mysql is deprecated. Commented Jun 29, 2012 at 16:51
  • 1
    Great informative question with good documentation. +1 Commented Jun 29, 2012 at 16:53
  • @David 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' Commented Jun 29, 2012 at 17:30
  • @David : I think aliasing to 'min' is doing something strange. please help Commented Jun 29, 2012 at 18:32
  • Unfortunately, I really don't have much experience with the php_mysql extension anymore, as I haven't used it in something like six years. was that 'Array' your entire result of print_r? The MySQL extension is doing something wacky or your query is invalid. Commented Jun 29, 2012 at 18:34

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

it seems $row['min'] has nothing in it as echo does not show anything
1
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

Comments

0

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

1 Comment

Thanks @justin but I am seeing true answer in phpmyadmin! please take a look at this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.