randydg Posted October 6, 2009 Share Posted October 6, 2009 I am trying to orginize the following code to order by date not id number. any help would be great <?php // Status // 1. inshop // 2 in progress // 3 pending // 4 to be picked up // 5 Done. Out of office. $db = mysql_connect("x","x","x") or die("Couldn't connect"); mysql_select_db("x",$db) or die("Couldn't select database"); $query="SELECT * FROM `calls` WHERE `status` = '1' AND `priority` != 1"; $result=mysql_query($query); $num=mysql_numrows($result); print '<table width="100%" border="0">'; print "<tr><td><b>In Shop: $num <br></b></td></tr>"; $i=0; while ($n < $numa) { $customer=mysql_result($result_customer,$n,"name"); $n++; }; $id=mysql_result($result,$i,"id"); $date=mysql_result($result,$i,"date"); $time=mysql_result($result,$i,"time"); $customer=mysql_result($result,$i,"customer"); // $worksheetnum=mysql_result($result,$i,"worksheetnum"); // $worksheetnum =mysql_result($result2,$i,"($_POST['worksheetnum'])"); $worksheet=mysql_result($result,$i,"worksheet"); #Find customer name out of customer field $query_customer="SELECT `name` FROM `customers` WHERE `id` = $customer"; $result_customer=mysql_query($query_customer); $numa=mysql_numrows($result_customer); $n=0; while ($n < $numa) { $customer=mysql_result($result_customer,$n,"name"); #end //View Inshop print '<FORM ACTION="GWS_online_lookup.php" method=post>'; print "<tr><td width=11%><input type=\"hidden\" name=\"wo\" value=$id><input type=\"submit\" value=\"View\"/>"; print "</td>"; print '<td align="left" width="29%">'; // print '<b><h3>'; print "$customer"; // print '</b></h3>'; print '</td><td width="24%">'; // print '<b><h3>'; print "$date"; // print '</b></h3>'; print '</td><td width="20%">'; // print '<b><h3>'; print "$time"; // print '</b></h3>'; print '<td width="16%">'; // print '<b><h3>'; print "WS $id"; // print '</b></h3>'; print '</td>'; print '</form>'; $n++; }; // $i++; // }; print "</table>"; $worksheetnum = trim(stripslashes($_POST['worksheetnum'])); $customerid = trim(stripslashes($_POST['customerid'])); $id = $_POST['wo']; print $worksheetnum; print "<input type=\"hidden\" name=\"worksheetnum\" value=$worksheetnum>"; print "<input type=\"hidden\" name=\"customerid\" value=$customerid>"; print "<input type=\"hidden\" name=\"wo\" value=$id>"; ?> Quote Link to comment Share on other sites More sharing options...
Jahren Posted October 6, 2009 Share Posted October 6, 2009 how about ORDER BY clause? $query="SELECT * FROM `calls` WHERE `status` = '1' AND `priority` != 1 ORDER BY theDate"; or $query_customer="SELECT `name` FROM `customers` WHERE `id` = $customer ORDER BY theDate"; link: http://www.w3schools.com/sql/sql_orderby.asp Quote Link to comment Share on other sites More sharing options...
randydg Posted October 6, 2009 Author Share Posted October 6, 2009 tried that didnt work Quote Link to comment Share on other sites More sharing options...
cags Posted October 6, 2009 Share Posted October 6, 2009 If theDate is the name of a column in the table that contains the date's you wish to order by, that is the correct syntax. Quote Link to comment Share on other sites More sharing options...
randydg Posted October 6, 2009 Author Share Posted October 6, 2009 yes, date is in the table. but when i put in there i get an error. $query="SELECT * FROM `calls` ORDER BY date WHERE `status` = '1' AND `priority` != 1"; and get error Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /www/htdocs/xxx/index.php on line 76 $num=mysql_numrows($result); Quote Link to comment Share on other sites More sharing options...
cags Posted October 6, 2009 Share Posted October 6, 2009 Well ORDER BY should be at the end also since date is a keyword you might wan't to also put it in backticks $query="SELECT * FROM `calls` WHERE `status` = '1' AND `priority` != 1 ORDER BY `date` "; Quote Link to comment Share on other sites More sharing options...
MatthewJ Posted October 6, 2009 Share Posted October 6, 2009 And like Cags posted, make sure it is inside backtics as date is a reserved word in mysql Ha... didn't see that the second half of your statement said the same thing I need coffee! 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.