Jump to content

Nested Loop Issue


mandrews81

Recommended Posts

I'm new to all this so excuse my ignorance.  I want to test a table to see how many rows have a 'Y' in the 'CONNECTED' column of my table.  If the row has a 'Y' then loop through the rows displaying the 'FIRST_NAME' and 'LAST_NAME' columns. 

If I just display the rows using:
[code]while ($row = oci_fetch_row($stid)) {
      echo "<p class=\"yellowSix\">" . $row[0] . " " . $row[1] . "</p>";
    }
[/code]

It works as expected but when I nest this in a test for number of rows it fails or in this case returns the else bracket of "No users online".  The code I'm using looks like:

[code]    $sql = "select FIRST_NAME, LAST_NAME from CONTACTS where CONNECTED = 'Y'";
  $conn = db_connect();
  $stid = oci_parse($conn, $sql);
  oci_execute($stid);
  $nrow = oci_num_rows($stid);
  if ($nrow > 0 ) {
      while ($row = oci_fetch_row($stid)) {
      echo "<p class=\"yellowSix\">" . $row[0] . " " . $row[1] . "</p>";
    }
  } else {
  echo "No users online";
  }
[/code]

Where did I go wrong?
Link to comment
Share on other sites

Query returns my first name and last name.  I'm the only users right now.
[code]
SQL> select FIRST_NAME, LAST_NAME from CONTACTS where CONNECTED = 'Y';

FIRST_NAME                    LAST_NAME
------------------------------ ------------------------------
B. Max                        Andrews
[/code]
Link to comment
Share on other sites

The 'Y' is inserted in the 'CONNECTED' column when the user logins in via a login function that issues an update to the table after authentication and the session has been started using the following statement. 

This part works as expected and I can query the table using SQL Plus after login and log off and the table is updated correctly.

[code]
$sql = "update CONTACTS set CONNECTED = 'Y' where CONTACT_ID = ";
$sql .= "'" . $_SESSION["user"]->contact_id . "'";
[/code]
Link to comment
Share on other sites

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.