Jump to content

Recommended Posts

Hello everyone

 

This code is used to show my guest list in a table on my website that is pulled from a database. It displays the guest list fine BUT I want it to be more selective to who is shown on the guest list. The following part is where I run into an issue:

if (($line % 2 == 1)&&($row["is_finalized"]=="yes"))

else if ($row["is_finalized"]=="yes")

 

I only want to display the people who are actually finalized on my list. is_finalized is a table in my database that either has a yes or no parameter. Please note that when I remove ($row["is_finalized"]=="yes") all the entries in my database display fine but when I add the condition I get no output but no error either.

 

Please let me know what the correct syntax is to use in an if statement pulling data from a database row.

The entire code is displayed below.

Thanks!

 

 

<?
class guests
{
  /* mysql data */
  var $db_host  = "private";
  var $db_user  = "private";
  var $db_pass  = "private";
  var $db_name  = "private";
  var $db_tbl   = "private";


  /* will be filled in constructor */
  var $fast_mode;
  var $color_line;
  var $url;


  /* constructor - executed on object creation */
  function guests()
  {
    // set to 1 to skip confirmation on status change
    $this->fast_mode = 0;

    // every second row will be filled with this color
    $this->color_line = "#e4c494";

    // links    
    $this->url["list"]    = "guestlist.php";

    // connect to mysql and select database
    $link = mysql_connect($this->db_host, $this->db_user, $this->db_pass);
    mysql_select_db($this->db_name, $link);
  }

  /* general list */
  function show_list()
  {
    $result = mysql_query("SELECT * FROM " . $this->db_tbl . " ORDER BY submission_id");

    echo "<table cellspacing=0 cellpadding=2 border=0>\n";
    echo "  <tr>\n";
    echo "	<td><b>ID</b></td>\n";
    echo "	<td width=80><b>First Name</b></td>\n";
    echo "	<td width=80><b>Last Name</b></td>\n";
    echo "	<td width=100><b>Alias</b></td>\n";
    echo "	<td width=100><b>Clan</b></td>\n";
    echo "	<td width=100><b>City</b></td>\n";
echo "	<td width=40><b>Paid</b></td>\n";
echo "  </tr>\n";

    $line = 1;
    while ($row = mysql_fetch_assoc($result)) {
      if (($line % 2 == 1)&&($row["is_finalized"]=="yes"))
        echo "  <tr bgcolor=" . $this->color_line . ">\n";
      else if ($row["is_finalized"]=="yes"){
        echo "  <tr>\n";	
      echo "    <td>" . $row["submission_id"] . "</td>\n";
      echo "    <td>" . $row["col_1"] . "</td>\n";
      echo "    <td>" . $row["col_2"] . "</td>\n";
  echo "    <td>" . $row["col_3"] . "</td>\n";
  echo "    <td>" . $row["col_4"] . "</td>\n";
  echo "    <td>" . $row["col_5"] . "</td>\n";
  echo "    <td>" . $row["col_7"] . "</td>\n";
  echo "  </tr>\n";
      $line++;
  	}
      }
echo "</table>\n";
    }
}
?>

I would set is_finalized to boolean in your database and then re-arrange your if statements a little. That way you can do this

$line = 1;
    while ($row = mysql_fetch_assoc($result)) {
      if ($row["is_finalized"])
      {
         $color_code=""; 
          if($line%2==1) {
           $color_code="bgcolor='".$this->color_line."'"; 
           }
        echo "  <tr ".$color_code. ">\n";

        echo "  <tr>\n";   
      echo "    <td>" . $row["submission_id"] . "</td>\n";
      echo "    <td>" . $row["col_1"] . "</td>\n";
      echo "    <td>" . $row["col_2"] . "</td>\n";
     echo "    <td>" . $row["col_3"] . "</td>\n";
     echo "    <td>" . $row["col_4"] . "</td>\n";
     echo "    <td>" . $row["col_5"] . "</td>\n";
     echo "    <td>" . $row["col_7"] . "</td>\n";
     echo "  </tr>\n";
      $line++;
        }
      }

like this

$line = 1;

    while ($row = mysql_fetch_assoc($result)) {

      if (strtolower($row["is_finalized"])=="yes")    // just in case it's Yes or YES

      {

        $color_code="";

          if($line%2==1) {

          $color_code="bgcolor='".$this->color_line."'";

          }

        echo "  <tr ".$color_code. ">\n";

 

        echo "  <tr>\n"; 

      echo "    <td>" . $row["submission_id"] . "</td>\n";

      echo "    <td>" . $row["col_1"] . "</td>\n";

      echo "    <td>" . $row["col_2"] . "</td>\n";

    echo "    <td>" . $row["col_3"] . "</td>\n";

    echo "    <td>" . $row["col_4"] . "</td>\n";

    echo "    <td>" . $row["col_5"] . "</td>\n";

    echo "    <td>" . $row["col_7"] . "</td>\n";

    echo "  </tr>\n";

      $line++;

        }

      }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.