SunQuest
 
           MySQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMySQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old April 14th, 2008, 01:45 PM
davekilljoy davekilljoy is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 davekilljoy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 16 m 24 sec
Reputation Power: 0
While($row = mysql_fetch_array($result)) problem

I'm super new to PHP and im trying to just display all results from a certain table but its not working out @ all =(. I have different data in different tables, and I'm not exactly sure how to make it work? Any help is appreciated, also i know how terrible the code is so let loose. =P

function get_songs() {
$conn = get_connection();
$query="SELECT * FROM songcontent ORDER BY date DESC";
$result=mysql_query($query);
while($row = mysql_fetch_array($result)) {
$songID = $row['songID'];
$userID = $row['userID'];

$query="SELECT songName FROM song WHERE songID='$songID'";
$result=mysql_query($query);
$songName = $row[1];

$query="SELECT user FROM user WHERE id='userID'";
$result=mysql_query($query);
$user=$row[0];

echo "$songName by $user";
}
}

Reply With Quote
  #2  
Old April 22nd, 2008, 10:14 PM
dykebert's Avatar
dykebert dykebert is online now
Contributing User
Click here for more information. Click here for more information
 
Join Date: Apr 2008
Posts: 206 dykebert User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 Days 5 h 38 m 4 sec
Reputation Power: 1
I'm not a PHP or MySQL expert, but from looking at the code the issue is that you reassign $result to a query that only returns a single row with the "Select songname ..." and Select user ..." queries.

I don't know the naming conventions but you should change the variable names. If you change the first one the others are fine. Perhaps something like:

$query="SELECT * FROM songcontent ORDER BY date DESC";
$resultAll=mysql_query($query);
while($row = mysql_fetch_array($resultAll)) {
...

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMySQL Development > While($row = mysql_fetch_array($result)) problem


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 4 hosted by Hostway