I recently started to use MySQL and PHP and am having a few problems.
what i want to do is to get the largest value of a primary key value and add one to to it so that i have a unique record. at the moment the table that i am using is empty (this is a possibility) and this is the code that i have:
$strMax = "SELECT MAX(SubscriberID) as maxID FROM tblSubscribers";
$objCheck = mysql_query($strMax);
$recCount = mysql_num_rows($objCheck);
if ($recCount > 0) {
$dbMaxVal = mysql_result($objCheck, "maxID"
if (($dbMaxVal != 0) || ($dbMaxVal != "") {
$maxIDVal = ($dbMaxVal + 1);
} else {
$maxIDVal = 1;
}
} else {
$maxIDVal = 1;
}
i have put in the mysql_num_rows line in as i get an error on the mysql_result line when the table is empty.
can anyone see anything wrong with this?
is there an easier way of achieving this?
cheers
Tony
what i want to do is to get the largest value of a primary key value and add one to to it so that i have a unique record. at the moment the table that i am using is empty (this is a possibility) and this is the code that i have:
$strMax = "SELECT MAX(SubscriberID) as maxID FROM tblSubscribers";
$objCheck = mysql_query($strMax);
$recCount = mysql_num_rows($objCheck);
if ($recCount > 0) {
$dbMaxVal = mysql_result($objCheck, "maxID"
if (($dbMaxVal != 0) || ($dbMaxVal != "") {
$maxIDVal = ($dbMaxVal + 1);
} else {
$maxIDVal = 1;
}
} else {
$maxIDVal = 1;
}
i have put in the mysql_num_rows line in as i get an error on the mysql_result line when the table is empty.
can anyone see anything wrong with this?
is there an easier way of achieving this?
cheers
Tony