Sponsored by NuSphere - PHP Software for PHP Application Developers - On Sale This Week for $100



Go Back   PHP-Editors > Linux, Apache, MySQL > MySQL Help

MySQL Help Post any question relating to MySQL here and hopefully someone can help

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2006-05-15, 11:33 AM
Junior Member
 
Join Date: Feb 2006
Posts: 4
freshrod
Default Query is double posting results?

I thought I had some problem with my PHP code at first, but then I took my code down to the bare essentials and I'm still getting this weird result.
When I run this simple query it prints out each field from the table twice and then moves on to the next field.
(i.e. userId, userId, userName, userName, userInfo, userInfo, etc, etc...)

Here's the code:

<?php

if (!($connection = mysql_connect("localhost", "root", "may1968")))
die ("Cannot Connect to DB!");

if (!(mysql_select_db("mhs", $connection)))
showerror();

function showerror() {
die ("Error " . mysql_errno() . " : " . mysql_error());

$result = mysql_query ("SELECT * FROM users WHERE userId = 1");

while ($row = mysql_fetch_array ($result))
{
foreach ($row as $stuff)
print "{$stuff} ";
print "\n";
}

?>

I've checked and double checked the DB with the MySQL Command Line Client and the table looks fine to me... no doubles there. Any ideas?
Reply With Quote
  #2 (permalink)  
Old 2006-05-15, 02:58 PM
Junior Member
 
Join Date: Feb 2006
Posts: 4
freshrod
Default

I actually figured this one out myself... FINALLY!!!

It was returning one set of data from the while loop and one from the foreach loop. So I was basically telling it to repeat it. Duh!
I had used code similar to this before, but it was when I was populating a list with several rows.

This can be considered resolved until my next fiasco! lol
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 11:07 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.