Jump to content

Chanching the order of a table


winter_kiter

Recommended Posts

Heres the code for the form and the dropdown lists. Took me a while to figure out how to set up the loops.

if ($_REQUEST['action'] == "todo")	{																echo "My <b><font color=\"red\">School</b></font> To Do List";								echo "<br><br>";				if ($_REQUEST['subaction'] == "edititem")						{				$query="select * from list_items where priority >= '1'  and l_id='$_REQUEST[l_id]' order by priority";				$results=mysql_query($query); 				echo mysql_error(); 				$e=mysql_fetch_array($results)?>					<form name="addtodo" method="post" action="todo.php?action=edittodo&l_id=<?=$e[l_id]?>&groups=<?=$e[groups]?>">								Item: <input type="text" name="item" size="10" value="<?=$e[item]?>"> Link: <input type="text" name="links" size="10" value="<?=$e[links]?>"> <input type="submit" value="Update!"><br>					</form><?		}					else				{						}										$query="select * from list_items where priority >= '1' and groups='school' order by priority";						$results=mysql_query($query); 						echo mysql_error(); 												while ($e=mysql_fetch_array($results))					{							$new=1;																					$rows = mysql_num_rows($results);							echo mysql_error();													echo "<select name=\"p\" onChange=\"MM_jumpMenu('parent',this,0)\">";														while ($new <= $rows)								{																			echo "<option value=\"todo.php?action=changepriority&oldpriority=".$e[priority]."&newpriority=".$new."&l_id=".$e[l_id]."&groups=".$e[groups]."\"";																					if ($e[priority] == $new )												{													echo " selected>".$new."</option><br>";																								}																									else													{															echo ">".$new."</option><br>";													}								$new++;								}															if ($e[links] == "")									{							echo "</select><a href=\"todo.php?action=deleteitem&l_id=$e[l_id]&delpriority='$e[priority]'&groups=$e[groups]\"><img src=\"delete.gif\" border=\"0\" height=\"20\" width=\"20\"></a><a href=\"todo.php?action=schooltodo&subaction=edititem&l_id=$e[l_id]\"><img src=\"edit.gif\" border=\"0\" height=\"20\" width=\"20\"></a>".$e[item]."<br><br>";									}							else							{																echo "</select><a href=\"todo.php?action=deleteitem&delpriority=$e[priority]&l_id=$e[l_id]&groups=$e[groups]\"><img src=\"delete.gif\" border=\"0\" height=\"20\" width=\"20\"></a><a href=\"todo.php?action=schooltodo&subaction=edititem&l_id=$e[l_id]\"><img src=\"edit.gif\" border=\"0\" height=\"20\" width=\"20\"></a><a href=\"".$e[links]."\">".$e[item]."</a><br><br>";							}									}										?>					<form name="addtodo" method="post" action="todo.php?action=addtodo">								Item: <input type="text" name="item" size="10"> Link: <input type="text" name="links" size="10"> <input type="submit" value="add!"><br>					<input type="radio" name="groups" value="school">School<input type="radio" name="groups" value="work">Work<input type="radio" name="groups" value="finance">Financial<input type="radio" name="groups" value="other">Other					</form>					<?									}

And heres the code to interact with the database and change the priority.

	if ($_REQUEST['action'] == "changepriority"){	// This is what happens when the old priority is Less than the new priority ===================================================================	if ($_REQUEST[oldpriority] < $_REQUEST[newpriority])			{			$newpriority=$_REQUEST[newpriority];			$oldpriority=$_REQUEST[oldprioirty];			$change=$newpriority - $oldpriority;			$other=$change+$oldpriority+1;						$query="update list_items set priority = priority - 1 where priority > '$_REQUEST[oldpriority]' and priority < '$other' and groups='$_REQUEST[groups]'";mysql_query($query);						$query="update list_items set			priority='$newpriority'			where l_id='$_REQUEST[l_id]' and groups='$_REQUEST[groups]'";			mysql_query($query);		}		//==========================================================================================================================================		//This is what happens when the old priority is greater than the new priority ==========================	elseif ($_REQUEST[oldpriority] > $_REQUEST[newpriority])			{						$query="update list_items set priority=priority+1 where priority >= '$_REQUEST[newpriority]' and priority <= '$_REQUEST[oldpriority]' and groups='$_REQUEST[groups]'";mysql_query($query);						$query="update list_items set			priority='$_REQUEST[newpriority]'			where l_id='$_REQUEST[l_id]' and groups='$_REQUEST[groups]'";			mysql_query($query);					}		//======================================================================================================}

And heres the SQL so you can make the table in your database. So its a little easier to see how its setup.

CREATE TABLE `list_items` (  `l_id` int(11) NOT NULL auto_increment,  `priority` int(11) NOT NULL,  `item` varchar(32) NOT NULL,  `links` varchar(64) NOT NULL,  `groups` varchar(16) NOT NULL,  PRIMARY KEY  (`l_id`)) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=21;

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...