Jump to content

Need help looping a counter to be added to specific rows in a database


TeamCIT

Recommended Posts

Hey guys, I'm not sure exactly how I would word this problem so I will describe what I am trying to accomplish first.  As of now I have a database with multiple "destinations" which are chosen by the user one at a time using a drop down list and Submit button on my web page.  I can successfully generate a list of the chosen destinations, however the problem arises when I attempt to display the destinations in the order selected by the user.  In the database there is an "ID" column, which is it's dropdown list Value.  I also have a "selected" column, which changed from a default "0" to a "1" if it was chosen.  I instead want to replace the "0" with a variable that increases each time a new item is chosen, so that I may list them in ascending order.  The approach I am attempting to take to solve this problem is to create a loop with the array created with the chosen destinations, to use a MySQL query to update the "selected" column in my database for that destination. 

 

Any help or insight is greatly appreciated, here is the part of my code that I am having problems with:

 

$orderCounter = 0;

if($_POST['submitted'] == true) {
$destChose = $_POST['destList'];

if($destChose >= 1) {

for(($destChose >=1; $destchose <15; $destChose++)
{
mysql_query("update destinations
    			set selected= $orderCounter
    			where id= $destChose");
$orderCounter++;
}

$result = mysql_query("SELECT dest_name, dest_addr 
			FROM destinations
			WHERE selected >= '1'");			



while ($row = mysql_fetch_array($result)) {

			echo "<li>";
			echo $row["dest_name"];
			echo "</li>";

}

 

Thanks in advance!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.