chadp1a Posted December 19, 2007 Share Posted December 19, 2007 Hi all! I was wondering if anyone may have an idea on how I would go about the following: I have a queue list of entries with that are numbered 0,1,2,3,4 etc....... 0 being the first and so on.... Now.. each of those has a textbox where I can type in a number of choice.. so for example I can type in. 0 1 2 0 4 I want the latest occurrence to reorder itself to the top... for example this would yield... 3 1 2 0 4 My data is being stored in an array for example.. each text box used queue_id[] respectively. Thanks alot.... Quote Link to comment https://forums.phpfreaks.com/topic/82332-queue-similar-to-netflix/ Share on other sites More sharing options...
chadp1a Posted December 28, 2007 Author Share Posted December 28, 2007 I believe I was able to figure it out. I have posted my code below. Would someone with greater knowledge and experience please look at this and tell me what may be redundant or for that matter... what would you possibly change.. I'm new so go easy on me Thanks alot! Brian <? $num_changes=0; if(isset($_POST['btnSubmit'])){ $prev=$_POST['queue']; // grab difference between current and previous queue for ($c=0;$c<6;$c++){ $diff[$c]=$prev[$c]-$c; } } // loop thru new array $counter=0; for($c=0;$c<6;$c++){ $change=$diff[$c]; if($diff[$c]=="0"){$new[$counter]=(int)$prev[$c];$counter++;} else{$new2[$c+$change]=$c;$num_changes++;} } // number of array items in new queue $count=count($new); // make changes for($c=0;$c<6;$c++){ if($new2[$c]!="" || $new2[$c]=="0") {$row=$c;$rows_to_move=$count-$row; for($t=$count;$t>0;$t--){ $start=$row+$t-1; $new[$start+1]=$new[$start]; } $new[$c]=$new2[$c]; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form name="queue" action="<? $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data"> <table border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td><div align="center">Queue</div></td> <!--<td><div align="center">Previous</div></td>--> <!--<td><div align="center">Difference</div></td>--> <td><div align="center">New</div></td> <!--<td>New2</td> <td>New3</td> <td>New4</td>--> </tr> <? for ($c=0;$c<6;$c++){ ?> <tr> <td> <div align="center"> <input name="queue[]" type="text" id="queue[]" size="2" value="<? echo $c; ?>" /> </div> </td> <?php /*?> <td><div align="center"> <input name="prev[]" type="text" id="prev[]" size="2" value=" <? echo $prev[$c]; ?> " /> </div></td> <td><div align="center"> <input name="diff[]" type="text" id="diff[]" size="2" value="<? echo $diff[$c]; ?>" /> </div></td><?php */?> <td><div align="center"> <input name="new[]" type="text" id="new[]" size="2" value="<? if(isset($_POST['btnSubmit'])){ echo $new[$c]; } ?>" /> </div></td> <?php /*?><td><div align="center"> <input name="new[]" type="text" id="new[]" size="2" value="<? echo $new2[$c]; ?>" /> </div></td> <td><div align="center"> <input name="new[]" type="text" id="new[]" size="2" value="<? echo $new3[$c]; ?>" /> </div></td> <td><div align="center"> <input name="new[]" type="text" id="new[]" size="2" value="<? echo $new4[$c]; ?>" /> </div></td><?php */?> </tr> <? } ?> <tr> <td colspan="7"><table border="0" cellspacing="0" cellpadding="0"> <tr> <td><label> <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" /> </label></td> <td> - Changes made: </td> <td><? if(isset($_POST['btnSubmit'])){ echo $num_changes; } ?></td> </tr> </table></td> </tr> </table> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/82332-queue-similar-to-netflix/#findComment-424745 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.