Jump to content

order in catalog


techker

Recommended Posts

Hey guy's i made a small catalog style for my body's shop,in the admin he inserts and deletes products.

 

but he would like to order the products the way he wants to,not by Id or ASC desc...

 

so i added a field order inserts 1 to 10 lets say.

 

so how can i do it so first there is not replicates and second when i do my query how can i make it order by numbering 1 to 10..

Link to comment
Share on other sites

when you insert new item(s) starting at position number x, all current items having a position number > x would need to have their position number UPDATEed to be their current value + the number of items that are being inserted.

 

an insert of new data would involve an UPDATE for the position number field for some of the current items, followed by an INSERT for the new data with it's now vacated position number(s).

Edited by mac_gyver
Link to comment
Share on other sites

 

can you correct this?

 
$num= $_POST['num'];
$CheckNum = mysql_query("SELECT Order from Products WHERE Order = '$num'");

while($test = mysql_fetch_array($CheckNum))

if ($test ) {
echo "Is not valide";
}

 

 

The correction you need is to stop using obsolete code that has been completely removed from the current php version. Use PDO. Your current code is also ripe for an SQL Injection attack. You never ever send user supplied data directly to the database.

 

https://phpdelusions.net/pdo

Edited by benanamen
Link to comment
Share on other sites

Maintaing a perfect sequence of integers will be painful, both for you and the admin. Why don't you decouple the technical implementation from the user interface? The admin could, for example, arrange the products with simple drag-and-drop and doesn't have to care at all about how exactly the ranks are stored. Then you're free to choose any implementation which is technically suitable without having to worry about nice-looking numbers. To avoid re-arranging products all the time, you could use large gaps or even foating numbers instead of integers.

Link to comment
Share on other sites

Maintaing a perfect sequence of integers will be painful, both for you and the admin. Why don't you decouple the technical implementation from the user interface? The admin could, for example, arrange the products with simple drag-and-drop and doesn't have to care at all about how exactly the ranks are stored. Then you're free to choose any implementation which is technically suitable without having to worry about nice-looking numbers. To avoid re-arranging products all the time, you could use large gaps or even foating numbers instead of integers.

 

I was going to suggest the same thing. But, I think this example is a closer fit to what the OP is requesting. It includes two methods (serialize and toArray) that can be used to get the order of the elements to be sent to the server to update the sort order.

Link to comment
Share on other sites

ya i think i need to site down with my body on this..lol

 

the drag and drop is a good idea..just need to make a database that will store the order that he sets it with an id.

 

then extract by order by..

 

 

Hey thx for the help guys!

Link to comment
Share on other sites

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.