Jump to content

Recommended Posts

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....

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/82332-queue-similar-to-netflix/
Share on other sites

  • 2 weeks later...

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.