Jump to content

PHP mysql structure


bitcycle

Recommended Posts

I have a database of music artist. I want the main page to show all artist. Then artist by genre with mainpage.php?cat=Rock.

My problem is not understanding what kind of statements I need to be researching to do this.This code below puts everything on one page. I think I need an if then statement but Im not sure how to state if this link is clicked echo this if that link is pressed echo that  This is what I have so far. Thanks. O yea I'm very new to this. I have 2 years of linux admin background and I'm starting to learn html php mysql.bye
[code]

<?
$db = mysql_connect("localhost", "root", "password");
mysql_select_db("db1",$db);
$result = mysql_query("SELECT * FROM db1",$db);
$result2 = mysql_query("Select artist FROM db1 where cat='$cat'",$db) or die(mys
while ($myrow = mysql_fetch_array($result))
{
echo "<TR><TD>";
    echo $myrow["artist"];
echo "</br>";
}
echo "</TABLE>";
While ($myrow2 = mysql_fetch_array($result2))
{
echo "<TR><TD>";
echo $myrow2["artist"];
echo "</br>";
}
echo "<TABLE>";
?>






[/code]
Link to comment
Share on other sites

I think you wanna something like:
[code]    // start where condition with void
    $where = '' ;
    // verify if cat is set
    if ( $_REQUEST['cat'] != '' )
    {
        // set where condition
        $where = ' where cat = "'. $_REQUEST['cat'] .'" ' ;
    }
    // mount the sql string
    $sql = ' SELECT artist FROM db1 '. $where ;
    // execute the query
    $result = mysql_query ( $sql , $db )[/code]
D.Soul
Link to comment
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.