query help

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!

Moderator: General Moderators

User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

ah that looks like what i want!

thanx for the help!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

isn't that the same as...

Code: Select all

SELECT MAX(whateverid) FROM table
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yes. I was assuming he'll have other things in there.. eventually
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

hi, one more question..

my q_id wont be auto_increment will it?

is there a way to add in 1, then 2, then 3 keep adding one?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

no on auto_inc

once you know the value needed, you can use an UPDATE query
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

i dont have to use a update do i?

i want to insert a question, that will be q_no=1

then insert another question, that will be q_no=2

then stop.

the come back and insert another question, that will be q_no=3

how can i do that kind of insert?

thanx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I have no idea why I said update... I meant insert.. I'm losing my mind today, I think.

.. not a news flash to some of you.. ;)

pretty much, you have to do a select to see what the current highest value is..
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

cool thats what i thought, i know as much as what you just said.

im just stuck at inserting one more value at a time.

what would my insert be?

thanx feyd
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

just a standard insert:

Code: Select all

INSERT INTO table (s_id, q_no, question) VALUES('3','5','How do I lop off someone''s head?')
provided your s_id is 3 and the next q_no is 5..
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

thanx feyd,

will i have to keep adding 1 all the time

for example

query=SELECT g_id FROM table WHERE s_id = $s_id ORDER BY g_id DESC LIMIT 1

query = query + 1

then insert?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that's how counter typically works.. ;)
Post Reply