I have a little script that pulls data from just 1 table, I just want to be able to click a link to arrange the data accordingly, all I am try ing to do is click a link and pass a name to the variables in the sol line link this
Sql line:
$result = @mysql_query('SELECT * FROM members2006 ORDER BY "$search" ASC');
To check the variable name is being passed I put this above the sql line:
echo 'search holds ' . $search;
When I click the link the variable is then output as firstname as required,
If i enter firstname into the sql line in place of the variable then the data is displayed as per firstname column in the table.
This is the first time I have tried this with php and cant see where I am going wrong. Can anyone see my error.
Ok in my original code I had no error but the results were just output in order of the unique id column and by clicking my version of the link nothing changed,
I still dont understand why my way could not see the info held in the variable however with your input when i click the link it does now output the data in the order wanted which is great.
Now my only problem is when the page 1st loads there is no info in the variable and I get this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\apache group\Apache\htdocs\sudbury\password\tmpmft81bevcp.php on line 490
when there is no value u need to provide atleast some value to query to execute
if($_GET['search'] =="")
{
$result = @mysql_query('SELECT * FROM members2006 ORDER BY firstname ASC');
}
else
{
$result = @mysql_query('SELECT * FROM members2006 ORDER BY '.$_GET['search'].' ASC');
}
ok i have managed to sort out my problem with an if statement like this
if ($search == ''){
$result = @mysql_query('SELECT * FROM members2006 ORDER BY id ASC' );
}else{
$result = @mysql_query('SELECT * FROM members2006 ORDER BY '.$_GET['search'] .' ASC' );
}
However can someone explain why I have to use the $_GET[] function in the sql query instead of being able to just put the variable name in there instead.
oh no we were both posting at the same time, however I came up with almost the same code which is good news for me. I notice your formatting is easier to read.
The $_GET variable is used to collect values from a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and it has limits on the amount of information to send
Thanks on the $_get, I understand using this when information is sent with a form but I looked though my book and cant see why i need it when the variable is sent via the url string like this ?search=firstname
Sorry if I am a bit slow on this just cant make sence of that one bit
Bookmarks