heydj1234 Posted January 12, 2013 Share Posted January 12, 2013 Hi i am having a problem getting the order by DESC in my table working correctly <p>All walks are listed in order with the latest at the top. Walks can be filtered by area using the drop-down box. The abbreviated Area ID's are as follows:<br/> YD - Yorkshire Dales<br/> LD - Lake District<br/> FB - Forest of Bowland<br/> WPM - West Pennine Moors<br/> PD - Peak District<br/> LOC - Local<br/> O - Other<br/></p> </div> <!-- Selects walk area --> <br /> <form id="form1" name="form1" method="post" action="walk_results.php"> <label>Area</label> <select name="area_id"> <option value="">All</option> <?php $sql_result = mysql_query("SELECT * FROM walk GROUP BY area_id ORDER BY walk_date DESC"); while ($row = mysql_fetch_assoc($sql_result)) { echo "<option value='".$row["area_id"]."'".($row["area_id"]==$_REQUEST["area_id"]? " selected" : "").">".$row["area_id"]."</option>"; }; ?> <!-- Submits walk area --> </select> </label> <input type="submit" name="button" id="button" class="styled-button" value="Select Area" /></form> <style type="text/css"> .styled-button { -webkit-box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; -moz-box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; box-shadow:rgba(0,0,0,0.2) 0 1px 0 0; border-bottom-color:#333; border:1px solid #6470ED; background-color:#6470ED; border-radius:3px; -moz-border-radius:5px; -webkit-border-radius:5px; color:#fff; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; text-shadow:#b2e2f5 0 1px 0; padding:2px } </style> </select> </label> <!-- Walk area results table --> <div id= "result"> <br /><br /> <table width="900" border="1" cellspacing="1" cellpadding="4"> <tr> <td width="84" bgcolor="#6470ED" align="center"><strong>Select Walk</strong></td> <td width="75" bgcolor="#6470ED" align="center"><strong>Walk Date</strong></td> <td width="360" bgcolor="#6470ED" align="center"><strong>Title</strong></td> <td width="64" bgcolor="#6470ED" align="center"><strong>Distance (Miles)</strong></td> <td width="85" bgcolor="#6470ED" align="center"><strong>Ascent</strong></td> <td width="78" bgcolor="#6470ED" align="center"><strong>Time</strong></td> <td width="67" bgcolor="#6470ED" align="center"><strong>Area Id</strong></td> </tr> <?php if ($_REQUEST["area_id"]<>'') { $search_area_id = "AND area_id='".mysql_real_escape_string($_REQUEST["area_id"])."'"; } if ($_REQUEST["from"]<>'' and $_REQUEST["to"]<>''){ } else { $sql = "SELECT * FROM walk WHERE walk_id>\"\"".$search_string.$search_area_id ; } $sql_result= mysql_query ($sql) or die ('request"Error"'.$sql); #echo "SQL $sql"; --- to view info --- $clicked =$_REQUEST["area_id"]; $sql= "SELECT * FROM walk WHERE area_id = '$clicked' ORDER BY walk_id"; if (mysql_num_rows($sql_result)>0) { while ($row = mysql_fetch_assoc($sql_result)) { $id = $row['walk_id']; $date_of_walk = $row['walk_date']; $date_of_walk = date("d.m.Y", strtotime($date_of_walk)); #echo "id $id<br>"; --- to view info --- ?> <!-- Table Results --> <tr> <td><?php echo "<a href='walk_info.php?walk_id=$id'>Select Walk"?></a></td> <td><?php echo $row['walk_date']=$date_of_walk; ?></td> <td><?php echo $row["title"]; ?></td> <td><?php echo $row["distance"]; ?></td> <td><?php echo $row["ascent"]; ?></td> <td><?php echo $row["time"]; ?></td> <td><?php echo $row["area_id"]; ?></td> </tr> <?php } } else { $row= mysql_fetch_assoc($sql_result);$sql_result= mysql_query ($sql); ?> <tr><td colspan="5">No results found.</td> <?php } mysql_close()?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 12, 2013 Share Posted January 12, 2013 The problem is? You've done what to debug it? There's nothing that stands out as a problem. Quote Link to comment Share on other sites More sharing options...
Christian F. Posted January 12, 2013 Share Posted January 12, 2013 Also, Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read. Thanks. One final thing: How did you define that "walk_date" field when creating the table? Quote Link to comment Share on other sites More sharing options...
heydj1234 Posted January 12, 2013 Author Share Posted January 12, 2013 Hi all Thanks for your replys It turned out to be this line $sql = "SELECT * FROM walk WHERE walk_id>\"\"".$search_string.$search_area_id ; It did not require the .$search_string onward to work it did take a while to figure it as the code worked it then needed sort by walk_ date DESC Thanks all Quote Link to comment 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.