query help
Moderator: General Moderators
query help
hi guys,
i have this query where i insert:
q_id - auto number (done)
s_id - fk (done
q_no -
q_text - (done)
now i got everything insert correctly except for the q_no.
now every time there is a new s_id the q_no will insert at 1 and increment up. example, 1, 2, 3, 4 ....
and if there is not a new s_id, i want it to carry on from where left off, for example, 4,5,6,7....
can anyone help me or give me a way on how i can achieve this?
thanx
i have this query where i insert:
q_id - auto number (done)
s_id - fk (done
q_no -
q_text - (done)
now i got everything insert correctly except for the q_no.
now every time there is a new s_id the q_no will insert at 1 and increment up. example, 1, 2, 3, 4 ....
and if there is not a new s_id, i want it to carry on from where left off, for example, 4,5,6,7....
can anyone help me or give me a way on how i can achieve this?
thanx
hey guys,
sorry about that heres some more info
now i want to add in the q_no, 1 2 3 4 5...
but now if i have a diff s_id (survey id) i want to carry on from where the q_no left off.
for example..
if the s_id is 3 and the q_no is 4, when im in the questions page and i insert another question i want that one to insert at no 5.
by the way its a online survey system might make it easier to understand. thanx!
sorry about that heres some more info
Code: Select all
<?php
session_start();
ob_start();
include("conection.php");
$sur_id = $_GETї'sur_id'];
if ($_SERVERї'REQUEST_METHOD'] == "POST")
{
$q_text = $_POSTї"txt_question"];
$sql = "INSERT INTO tbl_question (s_id,q_text) VALUES ('$sur_id','$q_text')";
$result = mysql_query($sql) or die ("Execution failed: ".mysql_error());
echo "sur_id: $sur_id";
header("Location: /survey/questions.php?sur_id=$sur_id");
echo "<br /><br /> <strong>new question added</strong> <br /><br />";
}
else
{
echo "<br /><br /> <strong>not added</strong>";
}
?>but now if i have a diff s_id (survey id) i want to carry on from where the q_no left off.
for example..
if the s_id is 3 and the q_no is 4, when im in the questions page and i insert another question i want that one to insert at no 5.
by the way its a online survey system might make it easier to understand. thanx!
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Code: Select all
SELECT g_id FROM table WHERE s_id = $s_id ORDER BY g_id DESC LIMIT 1