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!
$sql3 = "SELECT page_id FROM $table";
$result3 = mysql_query($sql3) or die ("Couldn't perform query -".mysql_error());
$row = mysql_fetch_array($result3);
$num = mysql_num_rows($result3);
// Get the last number in the array of page_id's
$last = $row[$num];
$new = $last+1;
... in order to generate a number for use later in the script. I was expecting "$row[$num]" to be the number stored in the last row of "page_id", but it's not: the only value I can get for $new is 1.
$sql3 = "SELECT page_id FROM $table";
$result3 = mysql_query($sql3) or die ("Couldn't perform query -".mysql_error());
$row = mysql_fetch_array($result3);
$num = mysql_num_rows($result3);
// Get the last number in the array of page_id's
$new = $num+1;
What I was trying to do was get the value of the page_id at row "$num", not $num itself. $num+1 would give me the number of rows +1, which I'm not interested in. What I want is the number stored in the last row (row "$num")...
But $num is only the numer of rows.
If you want to have a value from a row, you have to use $row['bla'], bla - the colum you are looking at.
With $num you have the total rows, so you know which is the last row.
Then only do a query on the last row.
$sql3 = "SELECT max(page_id) page_id FROM $table";
$result3 = mysql_query($sql3) or die ("Couldn't perform query -".mysql_error());
$row = mysql_fetch_array($result3);
// Now add 1 to the max value to get next value
$new = $row['page_id ']+1;
Am I mistaken in thinking that asking for $row['$num'] (e.g. $row['16']) should return the value of page_id at row 16?
If so, how do I use $num to perform the query as you recommend? I wasn't aware that you could query rows where you didn't know their value. In this case, the number contained in page_id will not necessarily be the same as $num.