mandrews81 Posted December 26, 2006 Share Posted December 26, 2006 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? Quote Link to comment Share on other sites More sharing options...
Vikas Jayna Posted December 26, 2006 Share Posted December 26, 2006 seems as if the query returned no records. Try running the query through the database interface and see if it returns some rows. Quote Link to comment Share on other sites More sharing options...
mandrews81 Posted December 26, 2006 Author Share Posted December 26, 2006 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] Quote Link to comment Share on other sites More sharing options...
Vikas Jayna Posted December 26, 2006 Share Posted December 26, 2006 Well! I'm assuming the database connections are properly set and the above code should work fine then. I wonder how the online list is maintained - is it through some flash file included in every page or something else? Quote Link to comment Share on other sites More sharing options...
mandrews81 Posted December 26, 2006 Author Share Posted December 26, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.