Missing Results using mysql_fetch_array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stylus
Forum Newbie
Posts: 17
Joined: Fri Dec 16, 2005 9:22 am

Missing Results using mysql_fetch_array

Post by stylus »

hello,

I have a table (users) with 4 records, when I do a select * from users and spit it out I only get 3 records. Using phpmyadmin I deleted all the records and recreated them, and still get the same results except it is a different record that is missing. It is the first of the 4 records that is missing.

Here is my code: I am baffaled.

Code: Select all

<?php include("config.php"); ?>
<?php 

mysql_connect($host, $user_name, $password) or die('Could not connect: ' . mysql_error());
mysql_select_db($database_name) or die('Could not select database');
$result = mysql_query("SELECT * FROM users") or die(mysql_error()); 
$row = mysql_fetch_array( $result ); 

echo ' <table width=100%><tr><td><strong>Company Address Book</strong> ';
		echo ' <table width=90% align=right><tr bgcolor=#eeeeee><td><strong>Name</strong></td><td><strong>Email</strong></td><td><strong>Cell</strong></td></tr> '; 
		while ($row = mysql_fetch_assoc($result))
			{
				echo "
					<tr>
						<td>$row[fname] $row[lname]</td>
						<td><a href=mailto:$row[email]>$row[email]</a></td>
						<td>$row[cell]</td>
					</tr>";
			}
		
		echo "</table></td></tr></table>";
?>

Config.php code:

Code: Select all

<?php
//config file
ob_start();
session_start();
//mysql info
$host = "#########";   //mysql host
$user_name = "#######";         //mysql username
$password = "########";                    //mysql password
$database_name = "########";     //mysql database name
$_login_file = "login.php";  		//login page
$redirect_url = "index.php";  		//main page;where it is redirected after login
?>
user info removed for security reasons.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

There was a Sherlock Holmes story called "The Case of the Fetching Row" in which there was a similar problem. Remove this line:

Code: Select all

$row = mysql_fetch_array( $result );
(#10850)
stylus
Forum Newbie
Posts: 17
Joined: Fri Dec 16, 2005 9:22 am

Post by stylus »

Thanks, that was one of those WTF!!! moments after a long day so I just gave up and went home.
Post Reply