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
https://forums.phpfreaks.com/topic/31887-nested-loop-issue/
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
https://forums.phpfreaks.com/topic/31887-nested-loop-issue/#findComment-147983
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
https://forums.phpfreaks.com/topic/31887-nested-loop-issue/#findComment-148001
Share on other sites

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.