Jump to content

sql ORDER BY help


Ali25m

Recommended Posts

Hi this is my first post and I'm after a little help if pos.  I've created a php based site to query a database and all is working fine, however I can't seem to get my results to order by a set criteria.  Any help is much appriciated.

 

p.s I am by no means an expert so any comments/suggestions are welcome.

 

 

<?php

include 'Remoteconnection.php';

error_reporting(0);

$error = "";

$d = $_POST['choice'];

$m = $_POST['month'];

$all = "All";

 

 

if ($_POST['hidden']==1)

{

$sq = "SELECT Date, Month, Time, bookingID, Ptime  FROM booking WHERE Date = '$d' and Month = '$m' ORDER BY Date";

$sres = mysql_query($sq) or die(mysql_error());

$count = mysql_num_rows($sres);

 

if ($d == $all)

{

$nsq = "SELECT Date, Month, Time, bookingID, Ptime FROM booking WHERE Month = '$m' ORDER BY Date";

$sqls = mysql_query($nsq) or die(mysql_error());

$count1 = mysql_num_rows($sqls);

}

}

?>

<?php

if (isset($_POST['delete']))

{

 

foreach($_POST['d'] as $id) {

 

$sqld = "DELETE FROM booking WHERE bookingid='$id'";

$result = mysql_query($sqld) or die (mysql_error());

}

}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

 

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<LINK REL=StyleSheet HREF="search.css" TYPE="text/css" MEDIA=screen>

</head>

 

<body>

 

<form method="post" action="http://www.whickhamschool.org/adminSearch.php">

<br/><br/><br/><br/>

<label for="choice"><b>Search By Month</b></label>

<br/><br/>

<label for="Date"><b>Date</b></label>

<br/>

<br/>

<select name="choice">

<option>1</option>

      <option>2</option>

      <option>3</option>

      <option>4</option>

      <option>5</option>

      <option>6</option>

      <option>7</option>

      <option>8</option>

      <option>9</option>

      <option>10</option>

      <option>11</option>

      <option>12</option>

      <option>13</option>

      <option>14</option>

      <option>15</option>

      <option>16</option>

      <option>17</option>

      <option>18</option>

      <option>19</option>

      <option>20</option>

      <option>21</option>

      <option>22</option>

      <option>23</option>

      <option>24</option>

      <option>25</option>

      <option>26</option>

      <option>27</option>

      <option>28</option>

      <option>29</option>

      <option>30</option>

      <option>31</option>

  <option>All</option>

 

</select>

<br/><br/>

<label for="Month"><b>Month</b></label>

<br/>

<br/>

<select name="month">

      <option>January</option>

      <option>February</option>

      <option>March</option>

      <option>April</option>

      <option>May</option>

      <option>June</option>

      <option>July</option>

      <option>August</option>

      <option>September</option>

      <option>October</option>

      <option>Novemeber</option>

      <option>December</option>

  </select>

<br/><br/>

<input type="submit" name="submit" value="submit">

<input type="hidden" value="1" name="hidden">

 

</form>

 

<strong><p>Please note if no data appears below then the bus has not yet been booked!</p></strong>

 

 

<table width="400" border="0" cellspacing="1" cellpadding="0">

<tr>

<td><form name="form1" method="post" action="http://www.whickhamschool.org/adminSearch.php">

<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">

<tr>

<td bgcolor="#FFFFFF"> </td>

<td colspan="4" bgcolor="#FFFFFF" ><h1>Bookings</h1></td>

</tr>

<tr>

<td align="center" bgcolor="#FFFFFF">ID</td>

<td align="center" bgcolor="#FFFFFF"><strong>Date</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>Month</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>Time</strong></td>

<td align="center" bgcolor="#FFFFFF"><strong>Pick up time</strong></td>

</tr>

<?php

if (isset($sqls))

{

while ($row2 = mysql_fetch_array($sqls))

{

?>

<td align="center" bgcolor="#FFFFFF"><?php echo  ' <input type="checkbox" name="d[]" value="' . $row2['bookingID'] . '" />';?></td>

<td bgcolor="#FFFFFF"><?php echo $row2[0];?></td>

<td bgcolor="#FFFFFF"><?php echo $row2[1];?></td>

<td bgcolor="#FFFFFF"><?php echo $row2[2];?></td>

<td bgcolor="#FFFFFF"><?php echo $row2[4];?></td>

</tr>

<?php

}

}

?>

<?php

while ($row1 = mysql_fetch_array($sres))

{

?>

<td align="center" bgcolor="#FFFFFF"><?php echo '<input type="checkbox" name="d[]" value="' . $row1['bookingID'] . '" />';?></td>

<td bgcolor="#FFFFFF"><?php echo $row1[0]; ?></td>

<td bgcolor="#FFFFFF"><?php echo $row1[1]; ?></td>

<td bgcolor="#FFFFFF"><?php echo $row1[2]; ?></td>

<td bgcolor="#FFFFFF"><?php echo $row1[4]; ?></td>

</tr>

<?php

}

?>

<tr>

<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete" onClick="javascript: return confirm ('Are you sure you wish to delete?')"></td>

</tr>

</table>

</form>

</td>

</tr>

</table>

 

</form>

</tr>

</table>

</div>

</div>

</body>

</html>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/207073-sql-order-by-help/
Share on other sites

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.