Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 16th, 2011, 05:10 AM
Authorized User
Join Date: Aug 2009
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Select statement looping results

Good morning! :)

I have a select statement that is returning the correct results but is looping the retrieved data over and over....

This is what I have:

$id = $_GET['id'];
$result = mysql_query("SELECT jobs.job_title,jobs.date,jobs.id,users.full_name,users.id FROM `jobs`,users WHERE jobs.user_id = $id ORDER BY job_title DESC LIMIT 10") or die(mysql_error()); 
echo "<table border='1'>";
echo "<tr> <th>Job Title</th> <th>Date Added</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
	// Print out the contents of each row into a table
	echo "<tr><td>"; 
	echo $row['job_title'];
	echo "</td><td>"; 
	echo $row['date'];
	echo "</td></tr>"; 


echo "</table>";
The result that it is returning looks something like this:

Job Title Date Added
Web Developer 2011-02-17
Web Developer 2011-02-17
Web Developer 2011-02-17
Sales Rep 2011-02-15
Sales Rep 2011-02-15
Sales Rep 2011-02-15
PHP Programmer 2011-03-07
PHP Programmer 2011-03-07
PHP Programmer 2011-03-07
Accountant 2011-02-15

As you can see it displays each record 3 times and then the next and so forth.

Any ideas how to change this would be highly appreciated.

Thank you in advance.
Reply With Quote
  #2 (permalink)  
Old March 18th, 2011, 09:43 AM
Friend of Wrox
Points: 2,473, Level: 20
Points: 2,473, Level: 20 Points: 2,473, Level: 20 Points: 2,473, Level: 20
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: May 2004
Location: India
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts

the code seems to be ok, please run the SQL query separately and see it returns the results correctly.

while($row = mysql_fetch_array($result)){
	echo $row['job_title']. " - ". $row['date'];
	echo "<br />";
Om Prakash Pant
Click the "Thanks" button if this post helped you.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looping Statement firefighter2045 Access VBA 13 January 18th, 2008 04:27 PM
Select from another select statement to a repeater simsen ASP.NET 2.0 Professional 0 May 2nd, 2007 04:34 PM
Looping Statement Solution KKeesling Visual Basic 2005 Basics 0 April 2nd, 2006 12:50 AM
Getting results from Select Multiple HTML tag dpjoff PHP How-To 9 February 2nd, 2004 04:03 PM

All times are GMT -4. The time now is 08:50 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.