TeamCIT Posted February 3, 2010 Share Posted February 3, 2010 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! Link to comment https://forums.phpfreaks.com/topic/190794-need-help-looping-a-counter-to-be-added-to-specific-rows-in-a-database/ Share on other sites More sharing options...
TeamCIT Posted February 3, 2010 Author Share Posted February 3, 2010 **Also I just realized I have syntax errors in my code from trying to fix a parse error I was getting, but I am working on fixing that now. If I need to go into more detail on something please feel free to ask Link to comment https://forums.phpfreaks.com/topic/190794-need-help-looping-a-counter-to-be-added-to-specific-rows-in-a-database/#findComment-1006093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.