RE: [PHP] why doesn't my code work? :(

From: Date: Wed, 19 Jul 2000 12:37:10 +0000
Subject: RE: [PHP] why doesn't my code work? :(
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-7253@lists.php.net to get a copy of this message
Have you tried echoing $query before it is passed to the database? If you do that, it will give you the query exactly as it is going to be passed to the database. You can then past your query into the mysql command line and see exactly what error is being produced by mysql. My guess is that you should change your $query to the following: $query = " SELECT * FROM releases_music ORDER BY desc LIMIT ".$offset.",10"; ....the first step mentioned is a good troubleshooting method when you aren't getting what you expect from your database query. Also, this is probably not the problem, but "desc" is a reserved word in mysql and can be used in an "order by" clause. So provided you have a field called DESC in your table, this should be ok as you have it. Just for your own sanity though, I would stay away from naming fields the same as reserved SQL keywords. HTH Sam Masiello System Analyst Chek.Com (716) 853-1362 x289 smasiello@chekinc.com -----Original Message----- From: Sandeep Hundal [mailto:sandeep_wde@yahoo.com] Sent: Wednesday, July 19, 2000 8:24 AM To: php-general@lists.php.net Subject: [PHP] why doesn't my code work? :( Hi ppl, I'm just trying a simple script to select something from a database, but it keeps giving me an error that there was a database problem (not selecting the database, but the second error mind you..) here's the code... : $offset = ($totalrows - 10); /* make connection to database */ MYSQL_CONNECT($hostname,$username,$passwrd) OR DIE("Oh twadi! Couldnt connect to the database, sorry mate!"); @mysql_select_db($dbName) or die("Unable to select database"); /* build the table from the database */ $query = " SELECT * FROM releases_music ORDER BY desc LIMIT $offset,10"; $result = mysql_db_query("$username", $query); if ($result) { print "<table border=0 cellspacing=0 cellpadding=0 width=100% align=center>\n"; while ($r = mysql_fetch_array($result)) { $name = $r["name"]; $date = $r["date"]; $starring = $r["starring"]; $others = $r["others"]; echo "<tr><td ><strong class=white>$name</strong></td> <td><small class=white>$date</a></small></td></tr>\n"; echo "<tr><td colspan=2><small class=white>$starring</small></td></tr> \n"; echo "<tr><td colspan=2><small class=white>$others</small></td></tr> \n"; } echo "</table><br> \n"; } else { echo "<strong class=black>whoops! there was some kind of database problem! It would be nice if you emailed the <a href=mailto:webmaster@snooplife.com>webmaster</a> and told him!</strong>"; } mysql_free_result($result); /* Close the database connection */ MYSQL_CLOSE(); Hope that makes sense to some folks... it gives me an error of : whoops! there was some kind of database problem! It would be nice if you emailed the <a href=mailto:webmaster@snooplife.com>webmaster</a> and told him! thanks in advance! /sunny __________________________________________________ Do You Yahoo!? Get Yahoo! Mail - Free email you can access from anywhere! http://mail.yahoo.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#7253) next »