Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
349 views
in Technique[技术] by (71.8m points)

php - mysql fetch array if no results display message

I am trying to get a database call to show a statement saying no results found if there are no results returned.

How would I go about doing this to my code:-

$getFixtures = mysql_query("SELECT ht.name AS hometeam_name, homescore, awayscore, at.name AS awayteam_name, time, date, week, comp.competition AS comp_name, se.name AS season_name
                    FROM fixture
                    JOIN team ht
                    ON ht.id = fixture.hometeam
                    JOIN team at
                    ON at.id = fixture.awayteam
                    JOIN competition comp
                    ON comp.id = fixture.competition
                    JOIN season se
                    ON se.id = fixture.season
                    WHERE se.name = '$season' AND comp.competition = '$competitiontitle' AND date >= '$today' AND at.name = '$teamName' OR ht.name = '$teamName' AND se.name = '$season' AND comp.competition = '$competitiontitle' AND date >= '$today'
                    ORDER BY date ASC
                    ");                     
                    while ($fixtureData = mysql_fetch_array($getFixtures))
                    {
                    $hfixteamlink = strtolower(str_replace(" ","-",$fixtureData['hometeam_name']));
                    $afixteamlink = strtolower(str_replace(" ","-",$fixtureData['awayteam_name']));
                    $date = date("d/m/Y", strtotime($fixtureData['date']));
                    ?> 

thanks in advance

Richard

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This needs an IF statement.

$rows = mysql_fetch_array($getFixtures);
if(count($rows))
{
    while ($fixtureData = $rows)
    ...
}
else
{
    echo 'No results found';
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...