Posted by admin under
MySql Artical
hello today I want to get the How to get the Next Auto Increment number in Mysql using PHP code ?
i found solution
Assuming id is the auto_increment column:
$query = mysql_query(“SELECT MAX(id) FROM `table`”);
$results = mysql_fetch_array($query);
$cur_auto_id = $results['MAX(id)'] + 1;
But this will create prob suppose you have deleted the max id of table suppose max id is 5 and deleted 5 and now run this it will return 5 buy mysql auto increment will use 6.
This function of mysql php to get next id. I fond a solution
$query = mysql_query(SHOW TABLE STATUS LIKE tablename);
$row = mysql_fetch_array($query);
$next_id = $row[‘Auto_increment’] ;
Here you will get next id.
thanks
mrphpguru
Posted by admin under
mysql queries
mysql query for a number of row inserted in a week
As what i am looking for is that i want to calculate number of rows inserted in the database in a week using mysql query..
So here is my solution for that..
first calculate the date of 7 days back using php
$sevendays = date(‘Y-m-d’, strtotime(“-7 days”));
so it is returning 7 days backs date.
now mysql query to find out the rows between today and seven days back date
Now let us move to select a range of records between two dates. Here is the sql for this
$NoResult = mysql_query(SELECT * FROM `dt_tb` WHERE dt BETWEEN ‘$sevendays’ AND ‘$today’);
So it will return a range of rows between two days…
now
$numToday = mysql_num_rows($NoResult);
So u got the noumber of rows in last 7 days using mysql and php
thanks
mrphpguru