One solution I found for checking if a primary key exists is to INSERT and see if you get an error, but that won't really work for my purposes because 98% of the time, I'm not interested in inserting a new record but in seeing which times are already taken.
Another solution I found was to use dba_exists, but the resource handle had me perplexed and I didn't know how to use the dba_open as opposed to what I've been using . . . mysql_connect and mysql_select_db.
Finally, in the book I'm working through, I thought I found the following solution, but unfortunately it's still listing all the times as available whether the primary key exists or not . . .
Code: Select all
for ($i = 8; $i < 22; $i += 2) {
$query = "SELECT * FROM reservations WHERE registration_date='{$primarykeysearch}'";
If (mysql_query ($query)) {
// list time as available
}
}(I didn't include the code where I built $primarykeysearch, but I ran SQL queries from phpMyAdmin so I know the queries were good . . . )