IT Community - Software Programming, Web Development and Technical Support

Why Does Foreach Display Each Loop Twice

This is a discussion on Why Does Foreach Display Each Loop Twice within the PHP Programming forums, part of the Web Development category; //this loop doesnt work as intended, each row displays twice, once with a number as $key and again with key ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 02-12-2009, 07:42 PM
hkp819 hkp819 is offline
D-Web Trainee
 
Join Date: Dec 2008
Posts: 41
hkp819 is on a distinguished road
Default Why Does Foreach Display Each Loop Twice

//this loop doesnt work as intended, each row displays twice, once with
a number as $key and again with key name as $key!?

Any ideas why?

$result = mysql_query("SELECT * FROM tbl WHERE id = Ƈ' ");
while($row = mysql_fetch_array($result)) {

foreach ($row as $key =$value) {

echo "<tr><td style='width:150px'>$key</td><td>$value</td></tr>";

}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sql loop Statement shaalini Database Support 17 12-15-2008 10:46 PM
Loop in Mysql Murali Database Support 0 02-12-2008 05:37 AM
Which is faster for array, while or for or foreach ? vivekanandan PHP Programming 1 07-20-2007 06:15 AM
Difference in for & foreach, exec vadivelanvaidyanathan Perl 0 07-15-2007 06:16 PM
Javaa:Tutorial - The Loop pranky Java Programming 0 02-23-2007 11:58 PM


All times are GMT -7. The time now is 07:04 PM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0