Jump to content

If Else does not display the Else results information


TecTao

Recommended Posts

I am having some trouble with what I thought would be a simple if else statement.  There are two pages. The first page has two entries, a pair of radio buttons that pass either a 1 or 2.  A text box that passes an ID number which is a string.

 

The second post page has 4 parts.  First passing the two variables with a $_Post.

Second a first if state qualifying if the first variable is a 1 or 2.  so it's If ( $groupID == 1 ).  If the groupID is 1, then it performs a sql query with the ID number and the an If Else from the results.

 

The first part of the if else queries the correct information.  All I'm trying to do is if there is no query to have a "no record" line but can't see to get it to work.  Here's the page 2 code for the group 1

 

What I am experiencing is that after the Else, the "no record" or any other text I put there is displayed.

 

<?php
//   <!-- Rep Code -->

if ( $groupID == 1 ) {
// start first if statement

$result = mysql_query( "SELECT * FROM users WHERE g_id = '$Id_number' AND userlevel = '9' " )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
  while ($row = mysql_fetch_array($result))
  {
     extract($row);
      
$g_idRep = $g_id ;

if(!empty($g_idRep)) {

echo $g_id;
echo "   ";
echo $g_admin_fname;
echo " ";
echo $g_admin_lname;
}
else
}

echo "no record";

}

$row_count++;
      }
mysql_close;

// end first if statement
}
?>

 

 

<?php
//   <!-- Rep Code -->

if ( $groupID == 1 ) {
// start first if statement

  if ($result = mysql_query( "SELECT * FROM users WHERE g_id = '$Id_number' AND userlevel = '9' " )) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_array($result)) {
        extract($row);
      
        $g_idRep = $g_id ;
        echo $g_id;
        echo "   ";
        echo $g_admin_fname;
        echo " ";
        echo $g_admin_lname;
      }
    } else {
      echo "no record";
    }
  }
}
?>

Your brackets are incorrect.

It helps to indent your code for easier reading :)

 

<?php
//   <!-- Rep Code -->

// start first if statement
if ( $groupID == 1 ) {

    $result = mysql_query( "SELECT * FROM users WHERE g_id = '$Id_number' AND userlevel = '9' " ) or die("SELECT Error: ".mysql_error());
    $num_rows = mysql_num_rows($result);
    while ($row = mysql_fetch_array($result))
    {
        extract($row);
        $g_idRep = $g_id ;
        if(!empty($g_idRep)) {
            echo $g_id;
            echo "   ";
            echo $g_admin_fname;
            echo " ";
            echo $g_admin_lname;
        }
        else
    }
    echo "no record";
}

$row_count++;
}
mysql_close;

// end first if statement
}
?>

 

As you can see most of the {} brackets are ending incorrect :)

 

This is what I can get out of your code:

<?php
//   <!-- Rep Code -->

// start first if statement
if ( $groupID == 1 ) {

    $result = mysql_query( "SELECT * FROM users WHERE g_id = '$Id_number' AND userlevel = '9' " ) or die("SELECT Error: ".mysql_error());
    if (mysql_num_rows($result)) {
        while ($row = mysql_fetch_array($result))
        {
            echo $g_id;
            echo "   ";
            echo $g_admin_fname;
            echo " ";
            echo $g_admin_lname;
        }
    } else {
        echo "no record";
    }
}
// end first if statement
?>

But if that's how it's supposed to work, I don't know.

That's up to you to tell us ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.