Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   Trouble Retrieving Records From Database (http://www.programmingforums.org/showthread.php?t=13434)

Satans_Banjo Jun 27th, 2007 11:15 AM

Trouble Retrieving Records From Database
 
Hi

I'm currently working on a website where people can submit links to music they have made. The submission form is now working (thanks to help from Styx) but now when I try to retrieve the contents of the database to display them on a page it doesn't seem to be able to. Here's the code I'm using to display them:

[php]
$username="*******";
$password="*******";
$database="*******";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die("Unable to connect to database");
$query="SELECT * FROM tunes";
$result=mysql_query($query);

$num=mysql_numrows($result);
mysql_close();

$i=0;

echo '<table border="1" align="center">
<tr>
<td colspan="4"><center>Database contents</center></td>
</tr>
<tr>
<td>Artist</td><td>Title</td><td>Genre</td><td>URL</td>';

while($i<$num)
{
$title=mysql_result($result,$i,"title");
$artist=mysql_result($result,$i,"artist");
$genre=mysql_result($result,$i,"genreID");
$url=mysql_result($result,$i,"url");
echo "<tr>
<td>$artist</td>
<td>$title</td>
<td>$genre</td>
<td>$url</td>
</tr>";
$i++;
}
echo "</table>";
[/php]

All the attribute names are correct and I'm doing things exactly the same as a tutorial said but this is how it's coming out:

http://www.electricjustice.com/viewtracks.php

As you can see, only the 'title' and 'url' attributes are being shown

Any advice?

Thanks

Banjo

Infinite Recursion Jun 27th, 2007 1:59 PM

Change query to be this:

$query="SELECT title,artist,genreID,url FROM tunes";

Then try this while loop...

:

while ($myrow = mysql_fetch_row($result))
{
    echo "$myrow[0]<br>$myrow[1]<br>$myrow[2]<br>$myrow[3]<br><p>"";
}


I haven't tested this, but it should work.

Satans_Banjo Jun 27th, 2007 4:47 PM

Quote:

Originally Posted by Infinite Recursion (Post 129724)
Change query to be this:

$query="SELECT title,artist,genreID,url FROM tunes";

Then try this while loop...

:

while ($myrow = mysql_fetch_row($result))
{
    echo "$myrow[0]<br>$myrow[1]<br>$myrow[2]<br>$myrow[3]<br><p>"";
}


I haven't tested this, but it should work.

Cheers, but I found out the problem. It wasn't the output, it was my HTML for my input that had the wrong field names :o

Infinite Recursion Jun 27th, 2007 7:55 PM

hah, always the small things eh?

Satans_Banjo Jun 28th, 2007 3:17 AM

Yeah - too much of the time


All times are GMT -5. The time now is 11:30 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC