show message on no results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deccypher
    New Member
    • Mar 2008
    • 14

    show message on no results

    HI the below code is working well with one exception if there is no results (which will happen a few times) then of course nothing is shown id like to put "sorry no results found here" of nothing is pulled from the database

    [CODE=php]$caslimitset = $_GET['caslimitset'];
    if ($caslimitset == "")
    {
    $caslimitset=4;
    }
    else
    {
    $caslimitset = $_GET['caslimitset'];
    }
    $whatid = $_GET['id'];

    $result7 = mysql_query(" SELECT *
    FROM `table`
    WHERE `size` = $sizeid
    ORDER BY `cases`.`id` DESC
    LIMIT $caslimitset ");

    while($r7 = mysql_fetch_arr ay($result7))
    {
    $id=$r7["id"];
    $ptno=$r7["ptno"];
    $heightmm=$r7["heightmm"];
    $widthmm=$r7["widthmm"];
    $depthmm=$r7["depthmm"];
    $size=$r7["size"];
    $manafacturer=$ r7["manafactur er"];


    echo"
    <li><span class='family-productname'><s trong>$title </strong></span><br />
    <img src='Images/products/cases/$ptno.jpg' width='100' height='80' /><br />
    <span class='family-productname'>
    $ptno</span></li>";

    }[/CODE]

    i have tried this
    [CODE=php]$caslimitset = $_GET['caslimitset'];
    if ($caslimitset == "")
    {
    $caslimitset=4;
    }
    else
    {
    $caslimitset = $_GET['caslimitset'];
    }
    $whatid = $_GET['id'];

    $result7 = mysql_query(" SELECT *
    FROM `table`
    WHERE `size` = $sizeid
    ORDER BY `cases`.`id` DESC
    LIMIT $caslimitset ");
    if ($result7 == "")
    {
    echo" sorry no results here";
    }
    else
    {
    while($r7 = mysql_fetch_arr ay($result7))
    {
    $id=$r7["id"];
    $ptno=$r7["ptno"];
    $heightmm=$r7["heightmm"];
    $widthmm=$r7["widthmm"];
    $depthmm=$r7["depthmm"];
    $size=$r7["size"];
    $manafacturer=$ r7["manafactur er"];


    echo"
    <li><span class='family-productname'><s trong>$title </strong></span><br />
    <img src='Images/products/cases/$ptno.jpg' width='100' height='80' /><br />
    <span class='family-productname'>
    $ptno</span></li>";

    }

    }[/CODE]

    but this dosent work and still shows nothing.

    can anyone help with this ( without having to so a 2nd query like a row count)

    Thanks
    Deccypher
    Last edited by Atli; Apr 12 '08, 12:41 AM. Reason: Changed [code] tags to [code=php].
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    i would use mysql_num_rows( ) on your mysql_query to return the number of rows affected by your query. If the number is less than one row
    [php]
    if(mysql_num_ro ws($_query) < 1)
    {
    "Nothing to display";
    }
    [/php]

    Regards

    Comment

    • Deccypher
      New Member
      • Mar 2008
      • 14

      #3
      Thanks, worked great

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        Originally posted by Deccypher
        Thanks, worked great
        No problem!

        See you around

        Regards:)

        Comment

        Working...