Help with code please

Im using a <h3> and <p> tags of an accordian to list enteries like shown below.
All entries under the <h3> must be in the <p> tags for the section

<h3>A</h3>
<p>Abe<br />
Apple<br />
</p>

my code is
<h3>A</h3>
<p><?php get_video(a); ?></p>

i want any videos beginning with the letter a to appear hear in a link
if there are videos in the database then i want them shown else a message saying sorry no videos added yet.

e.g.1: <p><a href=“video.html?id=1”>Abe Video</a><br />
<a href=“video.html?id=2”>Apple Video</a><br /></p>

e.g.2: <p>Sorry no videos are added yet</p>

i cannot get the no videos message to appear. i dont know how to get it to show that there is no video in the db

MY PHP BELOW

function get_video($letter){
$sql = "SELECT * FROM amc_videos ";
$sql .= "WHERE title LIKE ‘$letter%’ AND hide = 0 ";
$sql .= “ORDER BY title ASC”;
$result = mysql_query($sql);
if(!$result){
$op = "<p>Error with query " . mysql_error() . “</p>”;
}else{
while($video = mysql_fetch_array($result)){
$id = $video[‘id’];
$title = $video[‘title’];
$op = “~ <a href=\“videos.html?id=$id\”>$title</a><br />”;
}
echo $op;
}
}

Are you showing the whole alphabet on one page? i.e. do you have A, B, C, D… sections available at once?

If so it’d much better to query the DB once for all non-hidden videos, and use PHP to sort by letter, than to query the DB separately for every letter of the alphabet.

To do this you might iterate over your result set and split it into another array depending on the first letter of the video name.

You can use [fphp]substr[/fphp] to look at the first char.

try an if condition on [FPHP]mysql_num_rows[/FPHP]

Awesome that worked perfectly thanks very much.
Still only a newbie really never thought of mysql_num_rows

Cheers

Instead of

if(!$result)

which will never be false if the query ran successfully (even if no records were returned)

use something like


if(mysql_num_rows($result) > 0){
     //loop through $result to create links
} else {
     //display message saying no videos found
}