PDA

View Full Version : Rearrange in SQL


murray
09-18-2009, 09:08 AM
We have some sort of SQL database which contains all of our products and we can create/delete/edit product information thru web form.

These products are shown in webpage as thumbnails and when we input new product, its thumbnail becomes first thumbnail in webpage and oldest product is last thumbnail.

We now need to rearrange products alot in that webpage. For instance product which product id is #2 changes to #413 and #413 becomes #401.

Our database don't have any way to rearrange these things thru our web form.

How we can do this using phpMyAdmin which is installed? Or are there any 3rd party desktop apps (for Macs) that are easier to do this?

If i click in phpMyAdmin left pane "product_element", then i see all our products listed. There is also column "productelement_id".

Thanks

abduraooft
09-18-2009, 09:51 AM
We now need to rearrange products alot in that webpage. For instance product which product id is #2 changes to #413 and #413 becomes #401. Is there any specific criteria for doing this? Or just in random? And do you really need to update the table or just randomise the select query output?

murray
09-18-2009, 10:29 AM
Is there any specific criteria for doing this? Or just in random?

Yes, there is specific criteria. We are going to put popular products to top.

And do you really need to update the table or just randomise the select query output?

Sorry, but i don't understand this. I'm SQL newbie. :)

Thanks

abduraooft
09-18-2009, 10:33 AM
Yes, there is specific criteria. We are going to put popular products to top.
So how do you decide the popularity of a product? Are you saving any kind of hit counter or something like that?

murray
09-18-2009, 01:44 PM
So how do you decide the popularity of a product? Are you saving any kind of hit counter or something like that?

No. We wrote to text doc what is new order of products. We could easily format it any way needed, if it needs to be machine readable or whateva.

Thanks again

Old Pedant
09-18-2009, 08:12 PM
Okay, just add a new field to that table. Should be able to do that via phpMyAdmin.

Maybe name the new field "popularity" and just make it an INT field.

And put the popularity of each product--1 through whatever--into that field.

You can leave any really UN-popular products NULL.

And then add this to the end of the query you are currently using to get the products for the web page:

SELECT ...
...
ORDER BY IfNull(popularity,999999)
LIMIT xxx

(Don't add the LIMIT if it's not already there. Just leave it alone if it is.)

If you can't figure out how to do this, you'll have to show us some of the code for your web page.