fastsol1
03-09-2011, 12:25 AM
Ok so this may be kind of lengthy to explain but I will try to make it easy to understand.
I have a mysql table with the normal stuff in it for products and one column is a INT that I use to set the display order of the products. Meaning if product 1 has an id of 1 but a display number of 3 it would display as the 3rd product on the page.
I have a admin panel for the products to be able to change all aspects of the product except the display order. What I am trying to do is something very similar to Netflix in the queue for your movies when they list all the movies and you can change the order you want them by changing the number in the text field next to the movie. Now I am not trying to do it like them cause the use javascript and I only need this to work upon posting a form not client side.
So basically I would have a list of products and next to them a text box prefilled with the display number from the db. I want to be able to change the number in the textbox and in the end check the other products to see if they have to be moved down or up a spot in the order based on what has changed in the textbox after submitting the form. At this point I can probably figure out the up and down thing but my struggle is trying to figure out the best way to make the form and run a check to see if anything has changed.
I truly have no idea of the right way to go about this. I have tried several different things and have really gotten nowhere. I think I need to have the textboxes come across as an array in the $_POST and maybe even some hidden fields the same way for the original order of the list.
I have provided the code I have currently and a link to a live page of the code - http://amewebdesigns.com/t.php
<?php
if(isset($_POST['cats']))
{
print_r ($cat = $_POST['cats']);
print_r ($old = $_POST['old']);
$pc = count($_POST['old']);
for($w=0; $w<$pc; $w++)
{
if($_POST['old']['$w']===$_POST['cats']['$w'])
{echo "same<br/>";}
else echo "different<br/>";
}
}
?>
<form method="post" action="">
<?php
$count = 5;
for($i=0; $i < $count; $i++)
{
echo "<input type=\"text\" name=\"cats[]\"/>";
echo "<input type=\"hidden\" name=\"old[]\" value=\"$i\" />";
}
?>
<input name="Submit1" type="submit" value="submit" />
</form>
I hope that I explained it well enough, if you have Netflix online or even Blockbuster online then this should be easy to understand the result I am after. Any suggestions or help will be appreciated for I have been pondering this for months and have been trying for days.
I have a mysql table with the normal stuff in it for products and one column is a INT that I use to set the display order of the products. Meaning if product 1 has an id of 1 but a display number of 3 it would display as the 3rd product on the page.
I have a admin panel for the products to be able to change all aspects of the product except the display order. What I am trying to do is something very similar to Netflix in the queue for your movies when they list all the movies and you can change the order you want them by changing the number in the text field next to the movie. Now I am not trying to do it like them cause the use javascript and I only need this to work upon posting a form not client side.
So basically I would have a list of products and next to them a text box prefilled with the display number from the db. I want to be able to change the number in the textbox and in the end check the other products to see if they have to be moved down or up a spot in the order based on what has changed in the textbox after submitting the form. At this point I can probably figure out the up and down thing but my struggle is trying to figure out the best way to make the form and run a check to see if anything has changed.
I truly have no idea of the right way to go about this. I have tried several different things and have really gotten nowhere. I think I need to have the textboxes come across as an array in the $_POST and maybe even some hidden fields the same way for the original order of the list.
I have provided the code I have currently and a link to a live page of the code - http://amewebdesigns.com/t.php
<?php
if(isset($_POST['cats']))
{
print_r ($cat = $_POST['cats']);
print_r ($old = $_POST['old']);
$pc = count($_POST['old']);
for($w=0; $w<$pc; $w++)
{
if($_POST['old']['$w']===$_POST['cats']['$w'])
{echo "same<br/>";}
else echo "different<br/>";
}
}
?>
<form method="post" action="">
<?php
$count = 5;
for($i=0; $i < $count; $i++)
{
echo "<input type=\"text\" name=\"cats[]\"/>";
echo "<input type=\"hidden\" name=\"old[]\" value=\"$i\" />";
}
?>
<input name="Submit1" type="submit" value="submit" />
</form>
I hope that I explained it well enough, if you have Netflix online or even Blockbuster online then this should be easy to understand the result I am after. Any suggestions or help will be appreciated for I have been pondering this for months and have been trying for days.