Using this code:

$query = "select * from `music` WHERE `music`.`catid` = '" . $catid . "'"; I cannot seem to add "ORDER BY artist so that it would be in alphabetical order.

Second issue:
What do I need to do to have Display X amount of records, and then at the top / bottom of table have something that says Next 20 Songs, and then if the person selects Next, on the next page it would say Next / Back.
Here is the complete code:

<?php
 $catid = '2';
 $sql = "SELECT `name` FROM `category` WHERE `category`.`catid` = '" . $catid . "'";
 $query = mysql_query($sql);
 $name_res = mysql_fetch_row($query);
 $name = $name_res[0];
$query = mysql_query($sql) or die('Error: ' . mysql_error());
?>
<h2> <?php echo "$name"; ?> </h2>
       <table width="485" border="1" cellpadding="2" cellspacing="0">
        <tr>
              <td><strong>Song Title</strong></td>
              <td><strong>Artist</strong></td>
         <?
           $i = 0;
           $len = @mysql_num_rows($rs);
           $cols = 1;
            while ( $i < $len )
           {
            echo "<tr>";
            for ($x = 0; $x < $cols; $x++, $i++)
           {
            if ( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
            echo "<td class=tdrow3>". $row["song_title"] ." </td>";
            echo "<td class=tdrow3>". $row["artist"] ." </td>";
           
           }
            echo "</tr>";
           }
         ?>
         <? }?>
        </table>

Thanks for the help.

Recommended Answers

All 6 Replies

Firstly

$query = "select * from `music` WHERE `music`.`catid` = '" . $catid . "'";

can be simplified to

$query = "SELECT * FROM `music` WHERE `catid` = '$catid'";

To order you would have

$query = "SELECT * FROM `music` WHERE `catid` = '$catid' ORDER BY `artist`";

Typically pagination is done in two ways:
1. Inside the query using LIMIT statements ie.,

SELECT * FROM `music` WHERE `catid`= '$catid' LIMIT $limitStart,20

2. Outside the query using loop limiters ie.,

for($i=$limitStart;$i<$limitEnd;$i++)

Also, is catid an integer or a varchar/text/memo field? If it is an integer surrounding it with quotes will break the query.

Shawn Thanks I will try this later. and let you know how it works out. Also, this is what's in the db for category.

`catid` int(11) NOT NULL auto_increment,

It's an integer so you must not surround it with quotes so you would do $query = "SELECT * FROM `music` WHERE `catid` = $catid";

i finished the pagination script you needed. PM me your email so i can send it to you.

commented: Keith is awesome +1

Can we see that code? Please....

I don't have it anymore. that post was from over a year ago. I don't have anything from that time after some hardware failure which resulted in me loosing everything on my hard drive.

Just make another thread and we assist you there.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.