Jump to content

Recommended Posts

Hello people,

 

Just a quick one (Hopefully)...

 

I want to have a list of songs to appear on a page in which the user can order them by:

 

Last added

Alphabetically(A-Z)

Size

 

Do i use MySQL? I know how to print results from mysql but i'd need help with creating a loop that printed the results until there were none left, also, while printing i need them to be put into a table.

 

But the main objective is to learn how to sort the information on the users page.

 

Thanks

 

Snooble

 

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/
Share on other sites

ok, what would i link to... for example table looks like:

 

Song Title       | Size      |  Date Added   |     Download Link
----------------------------------------------------------
I'm an elephant| 2.3mb   |     20.2.07      |      Download    

 

When i click song title it orders in alphabetical... so... Order by (name of field)

 

Got it, but how do i link to that command? 2 ways i think of, one... linking to a different .php file with the sql in it. two. sql injection... SELECT * FROM (tablename) ORDER BY (fieldname)...

 

Best way?

 

Snooble (Thank you)

 

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/#findComment-189411
Share on other sites

Just make your links pass the order by clause through the url. eg;

 

<a href="display.php?orderby=title">Song Title</a>

 

Then, on display.php have something like.

 

<?php
  if (isset($_GET['orderby'])) {
    $order = $_GET['orderby'];
  }
  $sql = "SELECT * FROM songs ORDER BY $order";
?>

 

Of course you would need to setup defaults and sanitize the input, but yeah, should give you the idea.

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/#findComment-189436
Share on other sites

There is a great way to do this using mod_rewrites.

 

It appears complicated at first but its weel woth the effort.

 

1.You construct your usrls, based on the information that you want in your queries.

 

ie mysite.com/artist/album/track.

 

2. You construct the mod_rewrite to read the url and transfer it into good ol fashined url's

 

ie mysite.com/find.php?artiste=this&album=&track=thenext

 

3. Then you build your SELECT Statement with this information

 

4. Bobs your uncle you have a user firendly, search engine friendly site with nice clean urls.

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/#findComment-189455
Share on other sites

htmlentities will do wont it?

 

Not at all. You'll want to prevent sql injection, the easiest way (in this case) is to limit the order by clauses available. eg;

 

<?php

  $valid = array('title','date','size');
  if (isset($_GET['orderby'])) {
    $order = in_array($_GET['orderby'],$valid) ? $_GET['orderby'] : 'title';
  } else {
    $order = 'title';
  }

?>

 

this will also impliment the default order by to be by title.

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/#findComment-189460
Share on other sites

thank you, i'll change title to date and then it'll show the last uploaded ;)

 

thank you... will post again when i have the table and that running...

 

So far i have www.wezzsmusic.ifastnet.com/WM/music.php

 

i want it to add cells to the table printing the song title etc in each cell...

 

I just need an example for a loop that will pull the information from the mysql table and into the seperate cells (creating a new one)...

 

Snooble

Link to comment
https://forums.phpfreaks.com/topic/39296-ordering-information/#findComment-189466
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.