hansschmucker
08-27-2006, 01:38 PM
Hi... I've got a bit of a problem here...
I want to insert a new row with entryid being the currently highest one + 1 (can't use autoincrement) and priority being the highest one with the current parent +1
So this is the string that I pass to mysql_query();
SELECT @highestentryid:=MAX(entryid) FROM `mvs_menuentries`;
SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent='1';
INSERT INTO `mvs_menuentries` (`entryid` , `priority` , `title` , `location` , `parent` )
VALUES (IFNULL(@highestentryid+1 , 1 ), IFNULL( @highestpriority+1 , 0 ), 'Label', 'http://', '1');
Nothing too complicated here (except IFNULL, for which the documentation is pretty confusing) and it works perfectly if I let PHP echo() it, then copy it to phpMyAdmin's SQL box and run it from there, however if I feed it into mysql_query() I get this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent=' at line 1
I don't have really any idea how to track such an error, so please, any help would be highly appreciated.
Here are some more information in case you need it:
MySQL function:
function mysql_menuentry_insert($parententryid,$label,$location){
$mysql_query="SELECT @highestentryid:=MAX(entryid) FROM `mvs_menuentries`;
SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent='".$parententryid."';
INSERT INTO `mvs_menuentries` (`entryid` , `priority` , `title` , `location` , `parent` ) VALUES (IFNULL(@highestentryid+1 , 1 ), IFNULL( @highestpriority+1 , 0 ), '".$label."', '".$location."', '".$parententryid."');
";
html_msg($mysql_query);
mysql_query($mysql_query);
html_msg(mysql_error());
return;
}
Table structure:
id int(10) UNSIGNED
entryid int(11)
priority int
location varchar(128)
parent int(11)
I want to insert a new row with entryid being the currently highest one + 1 (can't use autoincrement) and priority being the highest one with the current parent +1
So this is the string that I pass to mysql_query();
SELECT @highestentryid:=MAX(entryid) FROM `mvs_menuentries`;
SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent='1';
INSERT INTO `mvs_menuentries` (`entryid` , `priority` , `title` , `location` , `parent` )
VALUES (IFNULL(@highestentryid+1 , 1 ), IFNULL( @highestpriority+1 , 0 ), 'Label', 'http://', '1');
Nothing too complicated here (except IFNULL, for which the documentation is pretty confusing) and it works perfectly if I let PHP echo() it, then copy it to phpMyAdmin's SQL box and run it from there, however if I feed it into mysql_query() I get this:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '; SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent=' at line 1
I don't have really any idea how to track such an error, so please, any help would be highly appreciated.
Here are some more information in case you need it:
MySQL function:
function mysql_menuentry_insert($parententryid,$label,$location){
$mysql_query="SELECT @highestentryid:=MAX(entryid) FROM `mvs_menuentries`;
SELECT @highestpriority:=MAX(priority) FROM `mvs_menuentries` WHERE parent='".$parententryid."';
INSERT INTO `mvs_menuentries` (`entryid` , `priority` , `title` , `location` , `parent` ) VALUES (IFNULL(@highestentryid+1 , 1 ), IFNULL( @highestpriority+1 , 0 ), '".$label."', '".$location."', '".$parententryid."');
";
html_msg($mysql_query);
mysql_query($mysql_query);
html_msg(mysql_error());
return;
}
Table structure:
id int(10) UNSIGNED
entryid int(11)
priority int
location varchar(128)
parent int(11)