isar21 Posted June 17, 2007 Share Posted June 17, 2007 Hello, without any known cause my Select-Statement seems to not work anymore (after four years without any trouble): <?php // Basic SELECT-Statement $select = "SELECT DISTINCT ID, city, address, day_time, conntact, URL"; $from = "FROM events"; $where = "WHERE ID > 0"; $how = "ORDER BY city LIMIT 0, 30"; ?> Now I got this message: Error: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'BY city LIMIT 0, 30' at line 1 In my php admin tool some content is still visbble some not, using the same Selct-Statement. Everything concerning the DB seems to be o.k. all the data is there. Any ideas what could be wrong there? Thanks a lot. Stephan Quote Link to comment https://forums.phpfreaks.com/topic/55970-solved-selct-statement-doesent%C2%B4t-work-anymore/ Share on other sites More sharing options...
Delixe Posted June 17, 2007 Share Posted June 17, 2007 You have to do ORDER BY city DESC DESC can be ASC, etc. Quote Link to comment https://forums.phpfreaks.com/topic/55970-solved-selct-statement-doesent%C2%B4t-work-anymore/#findComment-276489 Share on other sites More sharing options...
bubblegum.anarchy Posted June 18, 2007 Share Posted June 18, 2007 ORDER BY defaults to ASC - no need to explicitly define the sort direction. isar21: post the complete SQL query, and also where the $select, $from, $where and $how variables are combined. Quote Link to comment https://forums.phpfreaks.com/topic/55970-solved-selct-statement-doesent%C2%B4t-work-anymore/#findComment-276563 Share on other sites More sharing options...
isar21 Posted June 18, 2007 Author Share Posted June 18, 2007 o.k., here comes the whole story: <?php $events = mysql_query($select . $from . $where . $how); if (!$events) { echo("</table>"); echo("<p>Fehler bei der Suche nach der Nachricht in der Datenbank!<br />". "Fehler: " . mysql_error() . "</p>"); exit(); } // permit breaks and paragraphs $address = ereg_replace("\r","",$address); $address = ereg_replace("\n\n","<p></p>",$address); $address = ereg_replace("\n","<br />",$address); $day_time = ereg_replace("\r","",$day_time); $day_time = ereg_replace("\n\n","<p></p>",$day_time); $day_time = ereg_replace("\n","<br />",$day_time); //print code to start the news table print("<table width=\"560\"border=\"0\"bgcolor=\"#ffffff\"cellpadding=\"1\"cellspacing=\"2\">"); while ($event = mysql_fetch_array($events)) { echo("<tr valign='top'>\n"); $id = $event["id"]; $city = htmlspecialchars($event["city"]); $address = htmlspecialchars($event["address"]); $day_time = htmlspecialchars($event["day_time"]); $conntact = htmlspecialchars($event["conntact"]); $URL = htmlspecialchars($event["URL"]); // start table with results print("<tr bgcolor='eeeeee' valign='top' halign='left'><td><font class='news-headline-2'>$city</font></td><td> </td><td> </td></tr>\n"); print("<tr valign='top' halign='left'><td class='news-content'>$address</td><td class='news-content'>$day_time<br><a href=\"http://$URL\" target=\"_blank\">$URL</a></td><td class='news-content'>$conntact</td></tr>\n"); print("<tr valign='top' halign='left'><td> </td><td> </td<td> </td</tr>\n"); } exit(); // closing table print("</table>"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/55970-solved-selct-statement-doesent%C2%B4t-work-anymore/#findComment-276983 Share on other sites More sharing options...
isar21 Posted June 18, 2007 Author Share Posted June 18, 2007 Somebody already showed me the solution. Some spaces were missing in the select statement. The working code looks like that: <?php // SELECT-Statement $select = "SELECT DISTINCT ID, city, address, day_time, conntact, URL "; $from = "FROM events "; $where = "WHERE ID > 0 "; $how = "ORDER BY city LIMIT 0, 30"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/55970-solved-selct-statement-doesent%C2%B4t-work-anymore/#findComment-277013 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.