bitcycle Posted December 8, 2006 Share Posted December 8, 2006 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 and artists all artists alphabatized by letter like mainpage.php?letter=R. The mainpage show every artist in the database, mainpage.php?=Rock shows artists in a category and mainpage.php?=letter show all artists starting with the same letter. I created a letter field in the database. I understand how to structure the first if statement (if mainpage.php?cat=rock print all all rock artists but im not sure how to combine two conditions. like if mainpage.php?letter=a print all artists that start with a and only those and not all everty artist with it. Do I need a if elsif statement?Thanks Here is what I have so farmark[code]$db = mysql_connect("localhost", "root", "miy5uxiv");mysql_select_db("db1",$db);#$result = mysql_query("SELECT * FROM db1 ORDER BY letter",$db);#$result2 = mysql_query("Select artist FROM db1 where cat='$cat'",$db) or die(mysql_error());#$myrow2 = mysql_fetch_array($result2);// start where condition with void $where = '' ; // verify if cat is set if ( $_REQUEST['cat'] != '' ) { // set where condition $where = ' where cat = "'. $_REQUEST['cat'] .'" ORDER BY artist ' ; } // mount the sql string $sql = ' SELECT * FROM db1 '. $where ; // execute the query $result = mysql_query ( $sql , $db );while ($myrow = mysql_fetch_array($result)){echo "<TR><TD>"; echo "<TD><a href=\"forumcode.php?id=".$myrow[id]."\">$myrow[artist]</a></br>";echo "</br>";}echo "</TABLE>";$wheretest = '';if ($_REQUEST['letter'] != ''){ $wheretest = ' where letter = "'.$_REQUEST['letter'] .'" '; }$sqltest = ' SELECT * FROM db1 '. $wheretest ;$resulttest = mysql_query ($sqltest , $db );$myrow2 = mysql_fetch_array($resulttest);echo "<TR><TD>";echo "<TD> $myrow2[artist]";echo "</table>"[/code] Link to comment https://forums.phpfreaks.com/topic/29889-php-structure/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.