Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
mysql_fetch_array || foreach() doesn't iterate
Old 04-24-2008, 01:20 PM mysql_fetch_array || foreach() doesn't iterate
Extreme Talker

Posts: 177
Trades: 0
Heres the 2 main lines of code:

PHP Code:
$Rec2 mysql_fetch_array(mysql_query("SELECT Username FROM users WHERE Username != '$_COOKIE[user]'")); 
and

PHP Code:
foreach($Rec2 as $rec)
                    {
                        echo 
$rec;
                    } 
There are 17 rows in the $Rec2 array, but the foreach statement echo's 1 username 2x, so it currently echos:

bkerrbkerr


Any ideas?

Last edited by kbfirebreather; 04-24-2008 at 01:24 PM.. Reason: spelling and wrong info
kbfirebreather is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-24-2008, 02:29 PM Re: mysql_fetch_array || foreach() doesn't iterate
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Are you sure your query returns what you think ?
Try to make an echo() of it in the web page, and run it on the server directly, it may be the problem.

As mysql_fetch_array returns an array(obviously), if you use PHP5, the interator interface allows you to go through the array with a simple foreach.
So, if your array contains 17 rows, it would display 17 results...

Try to do a
PHP Code:
$Rec2 mysql_fetch_array(mysql_query("SELECT Username FROM users WHERE Username != '$_COOKIE[user]'"));
echo
"<pre>".print_r($Rec2,1)."</pre>"
to dump the structure of the array returned from your query.
Maybe you will spot something
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-24-2008, 02:49 PM Re: mysql_fetch_array || foreach() doesn't iterate
Extreme Talker

Posts: 177
Trades: 0
I did that and this is the output of the array

Code:
Array
(
    [0] => bkerr
    [Username] => bkerr
)
is there a better way of getting all the usernames from a table?
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Old 04-24-2008, 04:10 PM Re: mysql_fetch_array || foreach() doesn't iterate
Extreme Talker

Posts: 177
Trades: 0
got it

mysql_fetch_assoc()
kbfirebreather is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql_fetch_array || foreach() doesn't iterate
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.22514 seconds with 12 queries