d_rewb Posted August 4, 2009 Share Posted August 4, 2009 Hi guys, I am new to the php and msql, so any help would be gratefully appreciated. Okay I am trying to add an ORDER BY to the statement below but after trying everything i know how all i keep getting an errors, would anyone know where to insert this please. Here is the code: <?php include "config.php"; $sql=mysql_query("select * from event_db where eddate like '".$keyword."%'", $con); $numrows= mysql_num_rows($sql); if($numrows==0) { print ("<center><span class='style15'>No Events in $keyword.</span></center>"); } else { while($row=mysql_fetch_array($sql)) { $id = $row["eid"]; $dismonth = $row["eddate"]; $name = $row["ename"]; $description = $row["edesc"]; $date = $row["edate"]; $location = $row["eloc"]; $showtime = $row["eshow"]; $price = $row["eprice"]; $contact = $row["econt"]; $website = $row["eweb"]; $sdate = $row["esdate"]; list($startyear,$startmonth,$startday) = explode("-",$sdate); $edate = $row["eedate"]; list($endyear,$endmonth,$endday) = explode("-",$edate); $image = $row["eimage"]; ?> What i am trying to have are the records shown in ascending order by date. thanks again d_rewb Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/ Share on other sites More sharing options...
dadamssg Posted August 4, 2009 Share Posted August 4, 2009 $sql=mysql_query("select * from event_db where eddate like '".$keyword."%'" ORDER BY eddate ASC, $con); Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890576 Share on other sites More sharing options...
d_rewb Posted August 4, 2009 Author Share Posted August 4, 2009 hi, thanks I tried that and it displayed an error "Wrong parameter count for mysql_query() " thanks d_rewb Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890635 Share on other sites More sharing options...
PFMaBiSmAd Posted August 4, 2009 Share Posted August 4, 2009 It would really help if you posted your query where you attempted to use ORDER BY (for all we know where you put it in the query is what caused the problem) and post the error you were getting (for all we know it had nothing to do with using ORDER BY.) Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890636 Share on other sites More sharing options...
patrickmvi Posted August 4, 2009 Share Posted August 4, 2009 Try it like this: $sql=mysql_query("select * from event_db where eddate like '".$keyword."%' ORDER BY edate ASC", $con); Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890638 Share on other sites More sharing options...
loushou Posted August 4, 2009 Share Posted August 4, 2009 quotes will get you everytime Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890652 Share on other sites More sharing options...
d_rewb Posted August 4, 2009 Author Share Posted August 4, 2009 Thanks for all your responses. patrickmvi: I have just tried that and it seems to be working. I will try it on another page and if all goes well I will close the topic. Thanks again for all your responses. Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890680 Share on other sites More sharing options...
aschk Posted August 4, 2009 Share Posted August 4, 2009 A tip for spreading code readability. Try this instead: <?php // Query with replacement token(s). $query = "SELECT * FROM event_db WHERE eddate LIKE '%s%%' ORDER BY edate ASC"; // Query with parameters. $query = sprintf($query, $keyword); // Query execution. $sql=mysql_query($query, $con); ?> Link to comment https://forums.phpfreaks.com/topic/168802-solved-order-by-newbie-help/#findComment-890689 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.