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!
$result = $db->sql_query("INSERT INTO ".$prefix."_link_names (linkid,uid,catid,name,url) "
."SELECT MAX(linkid)+1,'$uid','$category','$name','$link' FROM ".$prefix."_link_names WHERE uid=$uid");
The issue is the "MAX(linkid)+1".
It works like a charm if there is a record in my table with the current uid, but if the user don't have a record in the table it creates a new record but no linkid. How do I get passed this?
There is AUTOINCREMENT field type in MySql that allows you to have unique record ids.
And your approach is potentially dangerous.
If two or more such inserts will be executed at the same time - there is a chance that two (or more) rows will be created with the same row-id
$result = $db->sql_query("INSERT INTO ".$prefix."_link_names (linkid,uid,catid,name,url) "
."SELECT MAX(linkid)+1,'$uid','$category','$name','$link' FROM ".$prefix."_link_names WHERE uid=$uid");
The issue is the "MAX(linkid)+1".
It works like a charm if there is a record in my table with the current uid, but if the user don't have a record in the table it creates a new record but no linkid. How do I get passed this?
SELECT MAX(`linkid`)+1 FROM `table`, '$uid', '$category')... etc
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.