Forum Moderators: coopster
Hey guys,
As you could as above I have titles and its data's where it's populating from oracle database (writeen in php and sql plus) , and arrows pointing up and down. At the moment I do not have arrow on my titles yet. The reason I have those arrows is that if someone click on those arrows, it has to sort files: \/ = descending /\ = ascending. I do not know where to start, I know it's weird. I am just wondering if anyone did something like this before, if so please help on me where to start?
Do i need more than one SELECT QUERY?
Thanks guys
Suresh
thispage.php?Order=Topic&Dir=DESC
up arrow like this
thispage.php?Order=Topic&Dir=ASC
With these variables you can then build up your query
$sql = "select * from yourtable orderby " . $_GET['Order'] . " " . $_GET['Dir'];
This is the basic principle. Of course, if you're concerned about security then you'll want to mask your field names and check you variables.
Tim
this is my query:
$result = mysql_query ("select id, etc, from mytable order by $_GET['Order'] . " " . $_GET['Dir']");
If I change to:
$result = mysql_query ("select id, etc from mytable order by " .$_GET['Order'] . " " . $_GET['Dir']); I get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource
try this
$sql = "select id, etc from mytable order by " .$_GET['Order'] . " " . $_GET['Dir'];
echo '<p>',$sql;
$result = mysql_query($sql) or die ('<p>'.mysql_error);
that will echo the actual query so you can see if it is missing anything and the 'or ide' will echo the actual error from mysql
$result = mysql_query($sql) or die ('<p>'.mysql_error());
jatar just left out the parentheses (I'm making all sorts of parse errors in code I post here too; most people who help you won't actually re-check their code since that takes time). You'll be able to identify these errors soon enough if you keep your nose in the php manual when you're coding.
But the error must be in: " .$_GET['Order'] . " " . $_GET['Dir'];
Without it there are no errors, the select is just fine.
Tried changing it, but only other errors.
echo $sql;
in fact, you might want to do:
$result = mysql_query($sql) or die ('<p>query: '.$sql.'<br />error: '.mysql_error());
this is just to help you on a little further, you'll probably encounter more errors - I have no idea what the " " is doing between the two get variables, but that's your business ;) (order by [NOTHING] - this should have triggered that little question, 'order by what?) - your $_GET variables apparently aren't showing up here. However, i'd spend some more time in sql tutorials, learning about variable scope, etc., you'll probably be drawing blanks like this a whole lot until you've brushed up some more. Focus on simpler code experiments where you understand more or less everything that's happening, and then move on to more challenging material.
ok let's recap
Timotheos' suggestion in msg 2 is a solid one. You add those values to your links and then you can resort the query based on the $_GET values.
the thing is those links need to be properly constructed
thispage.php?Order=Topic&Dir=DESC
this would be the link to a descending search on whatever column you chose, where 'Topic' would be the column name and 'Dir' would be the direction in which to sort them.
then
$sql = "select * from yourtable orderby " . $_GET['Order'] . " " . $_GET['Dir'];
you can read here about why that query is tructured that way
[dev.mysql.com...]
The link is properbly constructed, at least it works although give an error
echo "<td><b><a href=reservas_ordenar.php?Order=llegada&Dir=ASC>Llegada</a></b></td> \n";
$sql = "select * from bookings orderby " . $_GET['Order'] . " " . $_GET['Dir'];
$result = mysql_query($sql);
if ($row = mysql_fetch_array($result)){
But it still donīt work....
On the link you gave me they explain normal order by, but not order rows from links.
[dev.mysql.com...]
Thanks,