FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


finding highest entries - select and insert statements - eff





regards
Dear guys,
I need some guidance with this php/mySQL statement.
The basic issue is that I need to first retrieve 2 max values in the database before I can insert the new statement. I can do it with 3 separate mySQL statemtents. I was wondering if there's a more efficient way of doing this?

Here is my statement:
$query = "SET @max_orderP = ( SELECT max( OrderNumP ) FROM CATEGORIES ); SET @max_orderC = ( SELECT max( OrderNumC ) FROM CATEGORIES ); INSERT INTO CATEGORIES(Name, OrderNumP, OrderNumC, Status, SessionID) VALUES ('THIS IS A TEST', @max_orderP+1, @max_orderC+1,'1','XXXXX')";
Any insight appreciated.

Thank you in advance

Wink Regards
AftershockVibe
Hmmm, am I correct in thinking that max_OrderP and max_orderC are just unique identifiers for records?

Could you explain a little as to why you need these two fields instead of just one? If you were just using one then I'd suggest you look at auto-incrementing fields. You might be able to do this anyway with two but they suggest this might be a little more complicated.

If (when you define your table) you have a field which auto-increments it will increment automatically for you every time you insert a row so you don't need to worry about adding 1 to each record.
Related topics
SQL Tutorial
Syndicate Rich Media
MySQL DB Backup script - minor problem
Help with PhpBB
Database on Frihost site
SQL creating limited user
Error connecting to mysql ; please help
mySQL Query/PHP code - get the highest value...
[Q] mysql probleempje [solved], [Q] Goede firewall?
my sql create user problem
how to create a link on 2 tables in phpmyadmin mysql
MYSQL?
Can someone create a mysql user for me on my website?
What to learn first?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.