Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php foreach loop

Options
  • 11-12-2005 2:27pm
    #1
    Registered Users Posts: 673 ✭✭✭


    Hey,

    Im trying to get a script that will take an input from a html form and then do the following.

    The script first checks a mysql table for a specific entry with a "LIKE" statement and then counts how many times it appears in the table. A new table is then automatically created which will store the result of the count query.

    The first query that will be made from the html form will be something like g1_w1_q1_o1, so the following code first checks how many times g1_w1_q1_o1 appears in the table and then it will put g1_w1_q1_o1 into a new table with a new field stating how many times it appeared.
    $query = "SELECT count(user_answer)
            From ".$week."_survey_results 
            WHERE user_answer
            LIKE '".$game."_".$week."_".$question."_".$option."'";
    		$results = mysql_query($query);
    
    		while ($row=mysql_fetch_array($results)) {
    
    		$insert_sql = "INSERT INTO ".$game."_".$week."_".$question."_option_frequency
    		(your_answer, count, date)
    		VALUES 
    		('".$game."_".$week."_".$question."_".$option."',
    		'".$row['count(user_answer)']."',
    		'".$todays_date."'
    		)";
    		$results2 = mysql_query ($insert_sql)
    			or die ("Invalid query: " . mysql_error());
    		}
    

    My problem is that i want it then to automatically increment g1_w1_q1_o1 to g1_w1_q1_o2 and perform the same task again. Then do it again for g1_w1_q1_o3, etc.

    I was thinking that i would probably have to use a foreach statement but im not sure how to go about doing it. Can anyone help?

    Thanks


Comments

  • Registered Users Posts: 673 ✭✭✭Bananna man


    Got it sorted (finally). Should have just been using a "while" loop.


Advertisement