Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 06-05-2009
Member
 
Join Date: Apr 2009
Posts: 29
Php variable increment problem

hi,
I'm creating a quiz in php which allows user to select All questions and answers that I have issue in a table to put a checkbox and then allow the trainer to choose which questions will be in the quiz and then store them in a table "quiz1" composed of: num, login, question, rep1, rep2, rep3, rep. so far it's good.

What I do now is that I want to insert in the num fields (not auto_increment) numbers from 1 to n such that n is the number of existing matter, but unfortunately I can not do so. Here is my code which is responsible for integration:

Code:
if ($ _SESSION [ 'login']! ='') 
($ Username = $ _SESSION [ 'login']; 

for ($ i = 1; $ i <$ _SESSION [ 'i'], $ i + +) ( 
if (isset ($ _POST [ 'choice'. $ i])) ( 
$ choice = $ _POST [ 'choice'. $ i]; 
$ sql1 = "insert into quiz1 values ('','$ pseudo','".$ choice [0 ]."','".$ choice [1 ]."','".$ choice [2]. "','".$ choice [3 ]."','".$ choice [4 ]."','".$ choice [5 ]."')"; 
$ res = mysql_query ($ sql1); 
) 
) 
)
And I tried to change it:
Quote:
if ($_SESSION['login'] != '')
{ $pseudo = $_SESSION['login'];
$req="select * from quiz1 where login='$pseudo'";
$res=mysql_query($req);
for($i=1;$i<$_SESSION['i'];$i++){
for($j=1;$j<mysql_num_rows($res);$j++){
if (isset($_POST['choix'.$i])){
$choix=$_POST['choix'.$i];
$sql1 ="insert into quiz1 values ('$j','$pseudo','".$choix[0]."','".$choix[1]."','".$choix[2]."','".$choix[3]."','".$choix[4]."','".$choix[5]."')";
$res = mysql_query($sql1);
}
}
}
but it does nothing. Please help me because I really need your help.
Reply With Quote
  #2  
Old 06-05-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Php variable increment problem

You need some views ... including your $ j to see if you do not try to insert variable that already exist.I advise you to make a request in your for loop (the one with the $ j), which will select in each round the number of max variable in your table.
Reply With Quote
  #3  
Old 06-05-2009
Member
 
Join Date: Apr 2009
Posts: 29
Re: Php variable increment problem

after reading your reply i have done the following changes
Quote:
{$pseudo = $_SESSION['login'];
$req="select * from quiz1 where login='$pseudo'";
$res=mysql_query($req);
//$resa=mysql_num_rows($res);
for($i=1;$i<$_SESSION['i'];$i++){
for($j=1;$j<$res;$j++){
$requete="select MAX(numquest) from quiz1 where login='$pseudo'";
$reponse=mysql_query($req);
$num=$reponse++;
if (isset($_POST['choix'.$i])){
$choix=$_POST['choix'.$i];
$sql1 ="insert into quiz1 values ('$num','$pseudo','".$choix[0]."','".$choix[1]."','".$choix[2]."','".$choix[3]."','".$choix[4]."','".$choix[5]."')";
$res = mysql_query($sql1);
echo"$num";
but it does nothing at all ....
Reply With Quote
  #4  
Old 06-05-2009
Member
 
Join Date: May 2008
Posts: 2,293
Re: Php variable increment problem

Try to put two echo to see the values:

echo "SESSION Value [i]:". $ _SESSION [ 'i']."< br /> ";
echo "Number enr found:". mysql_num_rows ($ res). "<br />";
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Php variable increment problem"
Thread Thread Starter Forum Replies Last Post
Problem solving scope of variable Maya Angelou Software Development 5 23-03-2010 10:10 AM
Comparing the post increment and pre increment operators in C Programming Hebrew Software Development 6 16-12-2009 06:31 PM
Problem of const variable and its reference KABIRA16 Software Development 3 04-09-2009 04:45 PM
Runtime Error 91 : Object Variable or with block variable not set Ryan21 Software Development 2 28-08-2009 07:51 PM
Problem with variable input in C program Zool Software Development 2 14-05-2009 09:43 PM


All times are GMT +5.5. The time now is 11:39 PM.