|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Please help
I have 2 questions:
1) How do you add together all the numbers in a column? 2) How do you get just the most recent addition to a column e.g. the last number in the id field. Thanks for your help. |
|
#2
|
|||
|
|||
|
Hi Bassplayer,
Please refer to the forum rules before posting any messages. Your subject does not follow our guidelines. As for your first question, can you elaborate a little further. I'm having a hard-time understanding... If you're looking to add all the values in a certain column (within a database), you can use the SUM() function which will return the result of the addition. Your second question: You can retrieve the last inserted ID using mysql_insert_id(), which will return the last id inserted into an auto-incrementing field (most likely your primary key). Hope that helps...
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
|
#3
|
|||
|
|||
|
Sorry about that, I should have read the rules. Your answers for both my questions are exactly what I was looking for. I was looking to add all the values in a certain column.
Thanks a lot. |
|
#4
|
|||
|
|||
|
I've been trying to use mysql_insert_id and haven't managed to get it working. I am trying to insert the value of the last entry into the id column into another column of my database. I have used
$query = "INSERT INTO $table (n) VALUES (mysql_insert_id())"; It's probably a silly mistake but please help me out. |
|
#5
|
|||
|
|||
|
Quote:
Try storing the value of the mysql_insert_id() into a variable and then use that variable in your next insert: Code:
$last_insert = mysql_insert_id(); $query = "INSERT INTO $table (n) VALUES ($last_insert)"; HTH! |
|
#6
|
|||
|
|||
|
Or... it's kinda lengthy but it works:
PHP Code:
Then just use: $query = "INSERT INTO $table (n) VALUES ($id)"; |
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > Please help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|