RETRIEVING PRODUCTS FROM A MYSQL DATABASE!

Hi all I am trying to display products dependent on the genre that is selected!

For example product page contains four genre’s.

ALL MUSIC
ROCK
ROMANCE
SCRUMPY AND WESTERN

From the above I want to link these to a products page which displays only them products selected from the genre!

Here is my code!

[php]

<? session_start(); ?> <?php require_once 'include/db_config.php'; $sql="SELECT * FROM products"; $result=mysql_query($sql); $genre=$_GET['genre']; echo '
    '; while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){ if ($row["genre"]==$genre||$genre=="all"){ echo '
  • '; echo '
    '; echo '
    '.$row["title"].'
    '; echo ''.$row["artist"].''; echo '
    '; echo ''.'£'.$row["price"].' - '.'Buy'; echo '
    '; echo '
    '; echo ''.$row['; echo '
    '; echo '
  • '; }} echo '
'; ?>

[/php]

I’m a newbie and don’t have a clue what im doing wrong. Thanks in advance.
Sorry if I have placed the code in wrong first time!

How are you database tables setup?

Hello hathead1990, i hope you are getting proper value in $_GET['genre']. According to data i have modify your current code as per your requirement. Use below code and reply back [php] <? session_start(); ?> <?php require_once 'include/db_config.php';

$genresql=’’;
if(!empty($_GET[‘genre’]) && $_GET[‘genre’] != ‘all’)
$genresql = “where genre=’”.$_GET[‘genre’]."’";

$sql=“SELECT * FROM products “.$genresql;
$result=mysql_query($sql);
echo ‘

    ’;
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
    echo ‘
  • ’;
    echo ‘
    ’;
    echo ‘<h5 onclick="parent.location=‘description.php?id=’.$row[“product_id”].’’”>’.$row[“title”].’’;
    echo ‘’.$row[“artist”].’’;
    echo ‘
    ’;
    echo ‘’.‘£’.$row[“price”].’ - ‘.’<button class=“buyButton” onclick=“buyPress”()”>Buy’;
    echo ‘
    ’;
    echo ‘<div onclick="parent.location=‘description.php?id=’.$row[“product_id”].’’“class=“descriptionImg”>’;
    echo '<img src=”’.$row[“thumb”].’" alt="’.$row[“title”].’"/>’;
    echo ‘’;
    echo ‘
  • ’;
    }
    echo ‘
’;
?>
[/php]

i hope this will helpful for you.
Reply your feedback
SR

Sponsor our Newsletter | Privacy Policy | Terms of Service