| 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. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 (permalink) |
| Status: Junior Member Join Date: Aug 2009 Posts: 1
![]() | 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. |
| | |
![]() |
| Thread Tools | |
| Display Modes | |
| |