Internet Marketing Business Forum


Internet Marketing Business Forum » MAIN FORUMS » Web Design & Programming » PHP and MySQL question?
Web Design & Programming Building websites, coding scripts or developing apps? html, css, javascripts, ajax, php, asp, java, c+, C++ and other geeky info is here.

Reply
 
LinkBack Thread Tools Display Modes
Old 08-01-2009, 03:55 PM   #1 (permalink)
 Sam H's Avatar
 
Status: Junior Member
Join Date: Aug 2009
Posts: 1
Sam H is on a distinguished road
Default PHP and MySQL question?

I'm trying to set up a page showing the contents of a database of musical scores I have online but have come across a few problems.

I've got an SQL database with a table within called "list". Within the table I have three fields, "name", "composer" and "price". Using the script below, everything goes fine until I click on the "composer" link in the table (the line saying <td><a href=\"browse_scores.php?composer={$row['composer']}\">{$row['composer']}</a></td>). I get an error message saying "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /www/surge8.com/c/l/e/clefandstave/htdocs/browse_scores.php on line 33". Anyone got any ideas? Let me know if you need any more details.

if (isset($_GET['composer'])) {
$query = "SELECT * FROM list WHERE list.composer = {$_GET['composer']} ORDER BY list.composer ASC";
} else {
$query = "SELECT * FROM list ORDER BY list.composer ASC";
}

echo '
<div id="body">
<table>
<tr><td>Score</td>
<td>Composer</td>
<td>Price</td>
</tr>';

$result = mysql_query ($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr><td><a href=\"view_score.php?name={$row['name']}\">{$row['name']}</a></td>
<td><a href=\"browse_scores.php?composer={$row['composer']}\">{$row['composer']}</a></td>
<td>\£{$row['price']}</td>
</tr>\n";
}

echo '</table></div>';

Thanks,
Sam.
When I pasted that in it missed out a load of code for some reason - hence it probably doesn't make sense! I was going to shove a picture of the code in here but I solved the problem before I got chance. Oh and there were bits before and after this so the code did work properly.

I put a "or die (mysql_error())" after defining $result which showed me what was wrong, which was that I needed quotes around {$_GET['composer']} in the initial $query definition at the top.

Cheers.
Sam H is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Reply
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -4. The time now is 09:20 AM.
Powered by vBulletin® Version 3.7.0 Beta 6
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.


Nav Item BG