<?php
$con= mysql_connect("localhost","root","");
$d=mysql_select_db("laabhaa_crm",$con);
$result=mysql_query("SELECT MAX(LT_8690)
FROM lead") or die(mysql_error());
if($row=mysql_fetch_assoc($result))
$a=$row['MAX(LT_8690)']+1;
?>
<input type="text" readonly="readonly" value="LT" style="width:16px;"/>/
<input name="LT_8690" type="text" value="<?php echo $a;?>" readonly="readonly" id="" style="width:60px;">
</td>
</tr>
Asked
Active
Viewed 54 times
-1

Mark Baker
- 209,507
- 32
- 346
- 385

Rahul Kashyap
- 1
- 3
-
What is this... Post your query as well – Sunil Pachlangia May 07 '15 at 12:59
-
The query is posted. Read it again Sunil. – Muhammad Abdul-Rahim May 07 '15 at 13:01
-
1Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard May 07 '15 at 13:02
-
i am not getting to increment $a value after 10 .when i run my program then its doesnt works – Rahul Kashyap May 07 '15 at 13:03
1 Answers
1
Your query is this:
SELECT MAX(LT_8690)
FROM lead
The way you're trying to access that field is like this:
$row['MAX(LT_8690)']
This is incorrect. The column's name is not MAX(LT_8690)
. The column doesn't have a name. Let's give it one, as such:
SELECT MAX(LT_8690) AS 'maxLt8690'
FROM lead
$row['maxLt8690']
I like this option because I get to be specific with names. This makes my code more readable, which helps me when I have to go back and update it.

Muhammad Abdul-Rahim
- 1,980
- 19
- 31
-
-
Your column is indeed named `LT_8690`. However, the column returned by `MAX(*)` does not have a name. You cannot access it using `MAX(LT_8690)` in PHP, because that is not the name of the field. The field has no name by default. You can alternatively access by index, but it's more convenient to access by name. – Muhammad Abdul-Rahim May 07 '15 at 13:19
-
so i want to access that column value maximam value so what will be query? – Rahul Kashyap May 07 '15 at 13:25
-
-
-
-
"; $sql="select img_path from matri where user_na='suresh'"; while($row=mysql_fetch_array($sql)) – Rahul Kashyap May 08 '15 at 13:29
-
-