Maximum Value from the table using MAX does'nt working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ullasvk
Forum Newbie
Posts: 21
Joined: Fri Feb 13, 2009 11:55 pm

Maximum Value from the table using MAX does'nt working

Post by ullasvk »

Hello friends,
I have a small problem in my code.
I have two tables 1. order_detail 2. inventory.
I want to take maximum value from the coloumn which is in the both tables and update it to new row in the order_detail table. the below code works, but only for the first time i.e., it takes the maximum value from the both table and add 1 to it and it updates, but after that it updates the table with value 2. I tried a lot but all in vain. Please any one help me.

Thanks in Advance

Code: Select all

 
 
$result1 = mysql_query("SELECT MAX(bun_no) from order_detail");
$a = mysql_fetch_array($result1);
$result2 = mysql_query("SELECT MAX(bun_no) from inventory");
$b = mysql_fetch_array($result2);
$c = ($a1>$b?$a1:$b);
$d = $c[0] + 1;
$result9 = mysql_query("UPDATE ORDER_DETAIL SET  BUN_NO = '$d' WHERE SL_NO ='$a[$i]'  ");
 
 
Last edited by ullasvk on Wed Mar 04, 2009 12:00 pm, edited 1 time in total.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Maximum Value from the table using MAX does'nt working

Post by Mark Baker »

$a1 or $a????

Code: Select all

 
$c = ($a1>$b?$a:$b);
 
Post Reply