1

I have this code:

<?php

$platform_id = 7;
$query="SELECT * FROM game WHERE game_id IN (SELECT game_id FROM game_platform WHERE platform_id=".$platform_id.") AND game_release BETWEEN '2015-08-01' AND '2015-08-31' ORDER BY game_release";

$result=mysqli_query($link,$query) or die (mysqli_error());


        echo"<table border=1>
        <tr>
            <th width=40px>Day</th>
            <th width=270px>Title</th>
            <th width=203px>Genre</th>
            <th width=203px>Developer</th>
            <th width=205px>Publisher</th>
            <th width=61px>Retail?</th>
            <th width=30px height=30px></th>
            <th width=104px>Note</th>
        </tr>";

        while($row=mysqli_fetch_assoc($result))
       {
        echo"
        <tr>
            <td> ". (new DateTime($row['game_release']))->format("j") ." </td>
            <td>{$row['game_name']}</td>

            <td>";
            $query="SELECT * FROM genre WHERE genre_id=".$row['game_genre']; 
            $genreresult=mysqli_query($link,$query);                                    $genrerow=mysqli_fetch_assoc($genreresult);
        echo $genrerow['genre_name'];
        echo "</td>
            <td>{$row['game_dev']}</td>
            <td>{$row['game_pub']}</td>
            <td>{$row['game_type']}</td>
            <td><a href=\"{$row['game_site']}\" target=\"_blank\"><img src=\"images/officialwebsite.png\" title=\"Official website\"/></a>
                <a href=\"{$row['game_trailer']}\" target=\"_blank\"><img src=\"images/youtube.png\" title=\"Trailer\"/></a></td>
            <td>{$row['game_note']}</td>
        </tr>";


       }

       echo"</table>";
?>  

I want to show a message when there are no releases in said month, because right now I get an empty table which is not really user-friendly nor visually attractive.

I found this code on this site, but I get a syntax error due to .isEmpty.

<?php

$platform_id = 7;
$query="SELECT * FROM game WHERE game_id IN (SELECT game_id FROM game_platform WHERE platform_id=".$platform_id.") AND game_release BETWEEN '2015-08-01' AND '2015-08-31' ORDER BY game_release";

$result=mysqli_query($link,$query) or die (mysqli_error());


        echo"<table border=1>
        <tr>
            <th width=40px>Day</th>
            <th width=270px>Title</th>
            <th width=203px>Genre</th>
            <th width=203px>Developer</th>
            <th width=205px>Publisher</th>
            <th width=61px>Retail?</th>
            <th width=30px height=30px></th>
            <th width=104px>Note</th>
        </tr>";

        if($result.isEmpty())
        echo "Unfortunately there are no releases this month!";

        else
        {

        while($row=mysqli_fetch_assoc($result))
        {
        echo"
        <tr>
            <td> ". (new DateTime($row['game_release']))->format("j") ." </td>
            <td>{$row['game_name']}</td>

            <td>";
            $query="SELECT * FROM genre WHERE genre_id=".$row['game_genre']; 
            $genreresult=mysqli_query($link,$query);                                    $genrerow=mysqli_fetch_assoc($genreresult);
        echo $genrerow['genre_name'];
        echo "</td>
            <td>{$row['game_dev']}</td>
            <td>{$row['game_pub']}</td>
            <td>{$row['game_type']}</td>
            <td><a href=\"{$row['game_site']}\" target=\"_blank\"><img src=\"images/officialwebsite.png\" title=\"Official website\"/></a>
                <a href=\"{$row['game_trailer']}\" target=\"_blank\"><img src=\"images/youtube.png\" title=\"Trailer\"/></a></td>
            <td>{$row['game_note']}</td>
        </tr>";


       }
       }

       echo"</table>";
       ?>

I kept reading and there doesn't seem to be another way, because while-loops don't have 'else's?

How can I solve this? Thanks!

2
  • Check echo" <tr> <td> ". (new DateTime($row['game_release']))->format("j") ." </td> <td>{$row['game_name']}</td> <td>"; Its having syntax error. Commented Apr 11, 2015 at 11:33
  • It's working fine though. I'm not saying there can't be any mistakes in the code, because I'm learning every day, but could you please explain which error you've spotted? Commented Apr 11, 2015 at 11:35

1 Answer 1

4

You seem to be mixing javascript and php as .isEmpty() is not a php function.

You need to check the row count before you display your table, so something like:

$result=mysqli_query($link,$query) or die (mysqli_error());
if (mysqli_num_rows($result) > 0) {
   // your table generation code
} else {
  echo "Unfortunately there are no releases this month!";
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes I did. This worked, thank you. I'm learning web developing on my own and indeed have some trouble when working with multiple languages at the same time.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.