PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
djwk
Forum Commoner
Posts: 56 Joined: Tue Mar 07, 2006 2:14 pm
Post
by djwk » Fri Jun 08, 2007 3:48 am
Here's my code:
Code: Select all
<?php
$search = $_GET['search'];
$server = "localhost";
$user = "***";
$pass = "***";
$db = "***";
mysql_connect($server, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$result = mysql_query("SELECT * FROM vidz
WHERE Artist='$search'") or die(mysql_error());
$row = mysql_fetch_array( $result );
echo "<a href=watch.php?id=".$row['id'].">".$row['Artist']." - ".$row['Track']."</a><br />";
?>
If i search Rihanna ($search = "Rihanna";). There are 2 videos in the database by Rihanna. This code only returns the first one.
How would I be able to edit this code to display every video by Rihanna?
djwk
Forum Commoner
Posts: 56 Joined: Tue Mar 07, 2006 2:14 pm
Post
by djwk » Fri Jun 08, 2007 4:20 am
Yea I fixed it just as you posted this.
Code: Select all
while($row = mysql_fetch_array($result)){
if($row['id'] == ""){
echo "No search results found.";
} else {
echo "<a href=watch.php?id=".$row['id'].">".$row['Artist']." - ".$row['Track']."</a><br />";
}
}