MYSQL / PHP GROUPING

Get help on web editors (Frontpage, Dreamweaver) and web languages (HTML, ASP, PHP).
Post Reply
rule69
Registered User
Posts: 66
Joined: 29 Aug 2007, 02:00
Location: Right Here
Contact:

MYSQL / PHP GROUPING

Post by rule69 »

well hmm where can i start im tryng to get data from a mysql db..(obvious one) ... anyways i wana only get the data if a certain column,(artist in this case) , has only one song.. if they have more then one i want it to be grouped into one link like so

Code: Select all

http://yourdomain.com/dl.php?alpha=a&artist=somthng

Code: Select all


function track($alpha,$cats)
{
 if($_GET['page']) // Is page defined?

    {

        $page = $_GET['page']; // Set to the page defined

    }else{

        $page = 1; // Set to default page 1

    }

$max = 10; // Set maximum to 10

 

$cur = (($page * $max) - $max ); // Work out what results to show

 

$getdata = mysql_query("SELECT * FROM `cr-mp3` WHERE alpha='".$alpha."'  ORDER BY `id`  DESC LIMIT $cur, $max") or die(mysql_error()); // select the results
$getdata2 = mysql_query("SELECT * FROM `cr-mp3` WHERE alpha='".$alpha."'  ORDER BY `id`  DESC LIMIT $cur, $max") or die(mysql_error()); // select the results2

$data = mysql_fetch_array($getdata); // get the data

 

$counttotal = mysql_query("SELECT * FROM `cr-mp3` WHERE alpha='".$alpha."' ") or die(mysql_error()); // select all records        

$counttotal = mysql_num_rows($counttotal); // count records

 

$total_pages = ceil($counttotal / $max); // dive the total, by the maximum results to show 

$pgy = $_GET['page'];
 if($pgy > 1)
 {
 $nxt_tag = "«";
 }
 else
 {
 $nxt_tag = "»";
 }


 	 while($sql3 = mysql_fetch_array($getdata2)) {
    $link = $sql3[0]; 
    $name = $sql3[2];
	  $artist = $sql3[1];
    echo "» ";
    echo "<a href=\"../get.php?step=1&id=$link\">";
        echo "$artist - $name";
    echo "</a><br />\n"; 
	}

for($i = 1; $i <= $total_pages; $i++) // for each page number

                {

                    if($page == $i) // if this page were about to echo = the current page

                        {
						
						
	
                            echo' '.$nxt_tag.' <b>' . $i .'</b> '; // echo the page number bold

                                } 
								
								else {

                            echo ' '.$nxt_tag.' <a href="?page=' . $i . '&alpha=' .$alpha. '">' . $i . '</a> '; // echo a link to the page

                        }

                }

 if($page > 1){ // is the page number more than 1?

                $prev = ($page - 1); // if so, do the following. take 1 away from the current page number

                echo '<br /><a href="?page=' . $prev . '&alpha=' .$alpha. '">« Previous</a>'; // echo a previous page link

                }


if($page < $total_pages){ // is there a next page?

                    $next = ($page + 1); // if so, add 1 to the current

                echo '<br/><a href="?page=' . $next . '&alpha=' .$alpha. '">Next »</a>'; // echo the next page link

                    }
					
					
					}
wells here is my function.. i can only get it to fetch ALL the info and group it by id. but now theres no use since all the tracks by a partiular artist will be all over the show :(
Image

XFIRE: fubu07
Post Reply