SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    if all values are the same

    Hi,

    Im trying to do an if statement based on if one field in every entry has the same value, in this case 0.

    Wondering if its possible. As you can see im selecting taster_Active from the database, then I wont to check if in every entry has 0 and if so show nothing, but even if one has a 1 instead it moves onto the else bit

    PHP Code:
    $q=mysql_query("select taster_Active from Offers") or die (mysql_error()); 
    $rows=mysql_fetch_assoc($q);
    ?>
    <div id="mainHome_Nav_Drop">
    <? if ($rows["taster_Active"] == "0") { ?>
    <p style="color:#FFFFFF">Nothing to see here</p>
    <? } else { ?>

  2. #2
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    911
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    got this sorted now by the seems:

    PHP Code:
    <div id="mainHome_Nav_Drop">
    <?
    $sql 
    "select taster_Active from Offers where taster_Active = '1'"
    $result mysql_query($sql) or error(mysql_error()); 
    if(
    mysql_num_rows($result) < 1)  
    ?> 
    <p style="color:#FFFFFF">Love it</p>
    <? } else {

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,095
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    PHP Code:
    <div id="mainHome_Nav_Drop"> 
    <? 
    $sql 
    "select COUNT(taster_Active) AS c from Offers where taster_Active = '1'";
    $result mysql_query($sql) or error(mysql_error());  
    $row mysql_fetch_assoc($result);
    if(
    mysql_num_rows($row['c']) < 1)   
    ?>  
    <p style="color:#FFFFFF">Love it</p> 
    <? } else {
    Effectively does the same, but instead of retrieving all rows (which you then don't use), just get the number of rows from MySQL, which is a lot more efficient!
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •