Reply
Old 11-13-2009, 12:21 PM need HELP
Junior Talker

Posts: 3
Trades: 0
can anyone teach me how to do loop for the script below.. thanks in advance..

Code:
<?php
require_once('config.php');
 
 $aid1=$_POST['Question-1'];
 $aid2=$_POST['Question-2'];
 $aid3=$_POST['Question-3'];
 $aid4=$_POST['Question-4'];
 $aid5=$_POST['Question-5'];
 $aid6=$_POST['Question-6'];
 $aid7=$_POST['Question-7'];
 $aid8=$_POST['Question-8'];
 $aid9=$_POST['Question-9'];
 $aid10=$_POST['Question-10'];
 
 $qid1=$_POST['qid1'];
 $qid2=$_POST['qid2'];
 $qid3=$_POST['qid3'];
 $qid4=$_POST['qid4'];
 $qid5=$_POST['qid5'];
 $qid6=$_POST['qid6'];
 $qid7=$_POST['qid7'];
 $qid8=$_POST['qid8'];
 $qid9=$_POST['qid9'];
 $qid10=$_POST['qid10'];
 
 
    // update vote counter
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid1' AND qid = '$qid1'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid2' AND qid = '$qid2'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid3' AND qid = '$qid3'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid4' AND qid = '$qid4'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid5' AND qid = '$qid5'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid6' AND qid = '$qid6'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid7' AND qid = '$qid7'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid8' AND qid = '$qid8'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid9' AND qid = '$qid9'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
 $query = "UPDATE answers SET acount = acount + 1 WHERE aid = '$aid10' AND qid = '$qid10'";
    $result = mysql_query($query) or die("ERROR: $query. ".mysql_error());
 
    // close connection
    mysql_close();
?>
wayz1229 is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 11-13-2009, 01:55 PM Re: need HELP
orionoreo's Avatar
Ultra Talker

Posts: 286
Name: Jerry
Trades: 0
PHP Code:
<?php
require_once('config.php');
 
 for (
$i 1$i<=10$i++) {
    
$aid $_POST['Question-'.$i];
    
$qid $_POST['qid'.$i];
    
    
// update vote counter
     
$query "UPDATE answers SET acount = acount + $i WHERE aid = '$aid' AND qid = '$qid'";
    
$result mysql_query($query) or die("ERROR: $query. ".mysql_error());
 }

 
// close connection
 
mysql_close();
 
?>
orionoreo is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to need HELP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.10589 seconds with 13 queries