Jump to content

[SOLVED] ORDER BY - Newbie help


d_rewb

Recommended Posts

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

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.)

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);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.