Urgent PHP help.

I have an assignment to do and am stuck.
the question is:
Modify findTrack.php to ensure that no more than 2 tracks from any artist are contained in a single playlist. Provide a suitable error message where appropriate.

The code i have so far is:
[php]<?php
include(“dbConnect.php”);

$playlistID=$_REQUEST[“playlistID”];
$playlistTrackID=$_REQUEST[“playlistTrackID”];

if (isset($_GET[“artist”])) {
$artistID=$_GET[“artist”];

// add code here to ensure that we do not already have 2 tracks by the
// selected artist already entered into this playlist (1a)

echo “

Choose an album

”;
$dbQuery=$db->prepare(“select * from albums where artistID=:artistID”);
$dbParams=array(‘artistID’=>$artistID);
$dbQuery->execute($dbParams);
echo “<div class=“bigMargin”>”.
    ”;
    while ($dbRow = $dbQuery->fetch(PDO::FETCH_ASSOC)) {
    $albumTitle=$dbRow[“title”];
    $albumID=$dbRow[“id”];
    echo “
  • $albumTitle
  • ”;
    }
    echo “
”.
“”;[/php]

thanks

You can always add LIMIT to your query to limit the number of rows returned.

[member=49048]Valkrider[/member] , that will not work without doing a union query.

OP, The following should get you going:
http://www.xaprb.com/blog/2006/12/07/how-to-select-the-firstleastmax-row-per-group-in-sql/

Sponsor our Newsletter | Privacy Policy | Terms of Service