Jump to content

Sorting menu order ? sort ? array ? structure ?


Recommended Posts

Hi

 

i have a problem about sorting data that is stored in my DB. Data in the DB is something like this

-------menu_order-------------------
stuffs-----1----------------
stuffs-----5----------------
stuffs-----4----------------
stuffs-----2----------------

1- )now i want to sort this data and print it to the screen. Is there anyway to do this ? i heard about there is a sort function but i m not sure about it ?

 

2-) As you noticed there is no "3". i want to sort whole data and after that i want it like " 1,2,3,4 ".. i have tried this code using arrays ( first time i m using array ) for to print the data... ( if that would work i ll try to sort ) but for to print data this code did not work.. : 

$i=0;
$array=array();
while( $i<num )
{
$menu_order = mysql_result($queriedsql,$i,"menu_order");
$array[$i]=$menu_order;
echo "$arr[$i]<br/>";

$i++;
} // assume i have done sql-check and included db and there is no problem 

 

3-) i was busy with c++ before. And there was stuctures .. Is it same as php ? How can i control whole data like this in DB easily ?

 

I ll be glad if you can answer any of my questions. I'm a newbie so i ll also be glad if your replies are clear.

Thanx in advance.

Link to comment
https://forums.phpfreaks.com/topic/83860-sorting-menu-order-sort-array-structure/
Share on other sites

Hmm I'm a little confused about what you're asking.  If you don't want to sort your data by a specific key or by a timestamp, then you need to add another field like "sortOrder" and sort by that.  The way you have yours "1,5,4,2" wouldn't make sense unless you have some key to sort by.  Please be more clear with your question so we can assist.

revraz is correct as long as you want to order by a current fieldname.  No matter what you'll want to use order by fieldname, but you might need to add a sortOrder field to order by.

 

Edit:  This of course depends on what exactly you want your output to look like.  If you want it sorted by title you wouldn't need to add a sort order.  But if you wanted to be able to control the sort, you would need to add a sort order field.

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.