Jump to content

Strange result from queries


Darkmatter5

Recommended Posts

Looking at this code

<?php
include 'library/config.inc.php';
require('C:\wamp\www\library\opendb.php');
$pagedb = "members";

$result = mysql_query("SELECT mem_username
					  FROM " .$dbname. "." .$pagedb.
					  " WHERE logged_in = '1'") or die(mysql_error());
$count = count(mysql_fetch_array($result));
echo "There are " .$count. " results!<br>";
while($row = mysql_fetch_array($result)) {
	echo $row['mem_username']. "<br>";
}

require('C:\wamp\www\library\closedb.php');
?>

 

Say there are 2 users in the table (john.smith and jane.smith), both with the logged_in field set to 1. Why does it only output this example:

 

There are 2 results!

john.smith

Link to comment
https://forums.phpfreaks.com/topic/112822-strange-result-from-queries/
Share on other sites

Excellent thanks!

Now how can I implement printing out all the users that have the logged_in field set to 1 with a "," in between each one.  The code I have does it, but it also does it to the last user name as well.  And grammatically that's wrong.  So how can I do this without putting a "," after the last user?

 

<?php
  include 'library/config.inc.php';
  require('C:\wamp\www\library\opendb.php');
  $pagedb = "members";

  $query = mysql_query("SELECT mem_username
    FROM " .$dbname. "." .$pagedb.
    " WHERE logged_in = '1'") or die(mysql_error());
  while($row = mysql_fetch_array($query)) {
    echo $row['mem_username']. ", ";
  }

  require('C:\wamp\www\library\closedb.php');
?>

 

I thought about using the mysql_num_rows code you last told me about, but I can't think of how to use it.

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.