Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 10th, 2003, 02:43 AM
wfactor wfactor is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 wfactor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
loop - only row 1 is looping

Hi all,

Currently in my mysql database there are 5 rows.

I have it looping, however it posts the 1st row 5 times ( cause I have 5 rows).

my output page displays the data via arrays ( so I can format the page better)

my code is on my laptop not connected to the web so I cant post the code sorry.

any help would be greatly appreciated.

Thanks,
Ben

Reply With Quote
  #2  
Old April 10th, 2003, 02:51 AM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 10 m 20 sec
Reputation Power: 6
RE: loop - only row 1 is looping

Without code it is hard to say. It sounds like you are not fetching another row from the database, but just redisplaying the first row you fetch 5 times.

Reply With Quote
  #3  
Old April 10th, 2003, 02:56 AM
wfactor wfactor is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 wfactor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: loop - only row 1 is looping

Thanks for the reply Matt.

ive got it to fetch arrays

not sure how to fetch rows and fetch arrays in the same query

Ben

Reply With Quote
  #4  
Old April 10th, 2003, 08:09 AM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: loop - only row 1 is looping

Well, a common way to display results is something like this:
php Code:
Original - php Code
  1.  
  2. <?php
  3.  
  4. //...
  5.  
  6. echo "<table><tr><td><b>Name</b></td><td><b>Whatever</b></td></tr>";
  7.  
  8. $query=mysql_query("SELECT * FROM people");
  9. while ($row=mysql_fetch_array($query)) {
  10.     echo "<tr>".
  11.          "<td>".$row["name"]."</td>".
  12.          "<td>".$row["whatever"]."</td>".
  13.          "</tr>";
  14. }
  15.  
  16. echo "</table>"
  17. ...
  18.  
  19. ?>

Reply With Quote
  #5  
Old April 10th, 2003, 09:14 PM
wfactor wfactor is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 14 wfactor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: loop - only row 1 is looping

I was trying to use this code, but I got the error's

Warning:mysql_num_rows(): supplied argument is not avalid MySQL result resource in c:/....

Warning:mysql_free_result(): supplied argument is not avalid MySQL result resource in c:/....

php Code:
Original - php Code
  1.  
  2. /* connect to mysql */
  3. $db = mysql_connect("localhost", "root");
  4.  
  5. /* select the db we want */
  6. mysql_select_db(news, $db);
  7.  
  8. /* attempt to get a result resource */
  9. $query = mysql_query("SELECT date,author,news FROM news", $db);
  10.  
  11. /* make sure our query returned something; not technically correct, read the docs for why */
  12. if(mysql_num_rows($query) >= 1){
  13.  
  14.  /* loop through the results until there are no more */
  15. while($row = mysql_fetch_array($query)){
  16.  
  17. /* print the results; the n is just to make 'View Source' look pretty */
  18. printf("%sn<br>%sn<br>%sn<br><hr>", $row["date"], $row["author"], $row["news"]);
  19.     }
  20. }
  21.  
  22. /* free up the result resource */
  23.  

Reply With Quote
  #6  
Old April 11th, 2003, 05:30 AM
xs0 xs0 is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Ljubljana, Slovenia
Posts: 760 xs0 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: loop - only row 1 is looping

After mysql_query(), do

echo mysql_error();

to see what the problem with the query is

Reply With Quote
  #7  
Old April 11th, 2003, 08:10 AM
TheIceman5 TheIceman5 is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 114 TheIceman5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: loop - only row 1 is looping

could it be the 'date'? that is a reserve word aint it?

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > loop - only row 1 is looping


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT