I need to query a data base for the largest id #. This needs to be done each time the script is run. This # then needs to be placed into a var. so it can be used as the upper range for rand(0, $Lastid).
I have tried
<?php
$db = mysql_connect("localhost", "axxxxxli", "xxxxxxxxxx");
mysql_select_db("dxxxxxxxst_com3",$db);
$result = mysql_query("SELECT * FROM random_db",$db);
-----------------I tried-----------------------
$Lastid = mysql_insert_id(); ......... // All I get from this is the #0
-----------------I also tried-----------------------
$Lastid = mysql_insert_id($result); ......... // This did not work at all No # returned.
-----------------I also tried-----------------------
$Query = "SELECT LAST_INSERT_ID()";
$Result = mysql_query($Query, $db);
$row = mysql_fetch_array($Result);
$Lastid = $row[0]; ................... // This also returnes only #0
if($ID) {
$Lastnum = $ID;
}else{
$Lastnum = rand(0, $Lastid);
}
printf("%s\n\n", $Lastnum);
printf("%s\n\n", $Lastid);
?>
Is there a way to do this with out having to capture the number when it is iinserted then storing it in a var. in my db table