Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 27th, 2007, 11:15 AM   #1
Satans_Banjo
Newbie
 
Join Date: Oct 2006
Posts: 15
Rep Power: 0 Satans_Banjo is on a distinguished road
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
Satans_Banjo is offline   Reply With Quote
Old Jun 27th, 2007, 1:59 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 27th, 2007, 4:47 PM   #3
Satans_Banjo
Newbie
 
Join Date: Oct 2006
Posts: 15
Rep Power: 0 Satans_Banjo is on a distinguished road
Quote:
Originally Posted by Infinite Recursion View Post
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
Satans_Banjo is offline   Reply With Quote
Old Jun 27th, 2007, 7:55 PM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,466
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
hah, always the small things eh?
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jun 28th, 2007, 3:17 AM   #5
Satans_Banjo
Newbie
 
Join Date: Oct 2006
Posts: 15
Rep Power: 0 Satans_Banjo is on a distinguished road
Yeah - too much of the time
Satans_Banjo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing BLOBs in a database - problem jonyzz Other Programming Languages 8 Jan 31st, 2007 4:38 AM
.NET/ADO/MSACCESS database hbe02 Other Programming Languages 4 Sep 8th, 2006 2:57 PM
searching an access database? designXperts.net Visual Basic .NET 12 Nov 27th, 2005 5:03 PM
Using ODBC to connect to a remote database in a C program bigi C++ 1 Mar 8th, 2005 3:19 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 5:11 PM.

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