query string problem :urgent
Posted: Thu Apr 06, 2006 7:01 am
Pimptastic | Please use
Pimptastic | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
hi all i am new to php i was working on some code and wanted to sort the result based on the user input
i.e sort all the fields based on user clicking on the header field sincle i am not able to explain it clearly i am pasting the code :Code: Select all
$order = '';
$sort = ' desc';
if ($_REQUEST['sort'] == ' desc') {
$sort = ' asc';
}
else{ $sort = ' desc';}
if ($_REQUEST['fn']=='code')
{
$order .= 'order by Code'.''.$sort;
}
if ($_REQUEST['fn']=='state')
{
$order .= 'order by State'.''.$sort;
}
if ($_REQUEST['fn']=='city')
{
$order .= 'order by City'.''.$sort;
}
if ($_REQUEST['fn']=='type')
{
$order .= 'order by Type'.''.$sort;
}
if ($_REQUEST['fn']=='supplier')
{
$order .= 'order by Supplier'.''.$sort;
}
$sql = mysql_query("SELECT * from ghacars $order")or die(mysql_error().__LINE__.__FILE__);
$numofrows = mysql_num_rows($sql);
echo "SELECT * from ghacars $order"."<br>";
=====****************************************
$query->param(-name=>'sort',-value=>$sort); [color=red][size=18][u][b]this is the place of confusion i have done the same thing in perl using this code what is the alternative of this in PHP[/b][/u][/size][/color] i have used the following options but are not working:
$QSTRING = $QUERY_STRING."sort= $sort";
but as nothing is going in the query string the code is not working i want sort should also go with fn i am trying to embedd this also in the query string but nothing is visible in the adresss bar that is why i could not check for $_REQUEST['sort'] there the initial check i want a solution for this plz this is URGENT
(((((((((((if ($_REQUEST['sort'] == ' desc') {))))))))
i have done this in perl but could not implement in PHP
==========*****************************
$subst=substr_replace($QSTRING, '', 0);
//echo $subst."/********************************";
$query1 = $subst.'&fn='.'code';
$query2 = $subst.'&fn='.'state';
$query3 = $subst.'&fn='.'city';
$query4 = $subst.'&fn='.'type';
$query5 = $subst.'&fn='.'supplier';
$sortimage1='';
if ($_REQUEST['fn']=='code' && $_REQUEST['sort']==' asc'){
$sortimage1 = ' <img src="../images/sort_dn_1.gif"></img>';
}
elseif($_REQUEST['fn']=='code' && $_REQUEST['sort']==' desc'){
$sortimage1= ' <img src="../images/sort_up_1.gif"></img>';
}
$sortimage2='';
if ($_REQUEST['fn']=='state' && $_REQUEST['sort']==' asc') {
$sortimage2 = ' <img src="../images/sort_dn_1.gif"></img>';
}
elseif($_REQUEST['fn']=='state' && $_REQUEST['sort']==' desc') {
$sortimage2=' <img src="../images/sort_up_1.gif"></img>';
}
$sortimage3='';
if ($_REQUEST['fn']=='city' && $_REQUEST['sort']==' asc') {
$sortimage3 = ' <img src="../images/sort_dn_1.gif"></img>';
}
elseif($_REQUEST['fn']=='city' && $_REQUEST['sort']==' desc'){
$sortimage3=' <img src="../images/sort_up_1.gif"></img>';
}
$sortimage4 = '';
if ($_REQUEST['fn']=='type' && $_REQUEST['sort']==' asc') {
$sortimage4 = ' <img src="../images/sort_dn_1.gif"></img>';
}
elseif($_REQUEST['fn']=='type' && $_REQUEST['sort']==' desc') {
$sortimage4 = ' <img src="../images/sort_up_1.gif"></img>';
}
$sortimage5 = "";
if ($_REQUEST['fn']=='supplier' && $_REQUEST['sort']==' asc'){
$sortimage5 = ' <img src="../images/sort_dn_1.gif"></img>';
} elseif($_REQUEST['fn']=='supplier' && $_REQUEST['sort']==' desc') {
$sortimage5 = ' <img src="../images/sort_up_1.gif"></img>';
}
?>
<TABLE WIDTH="80%" ALIGN="CENTER" BORDER="0" CELLPADDING="3" CELLSPACING="1">
<th> </th>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"'
ONMOUSEOUT='style.background="#B3B8A5"'><font face="verdana,arial"
size=-1><a href="ghacarrental.php?<?=$query1?>">Serial</a></font><?=$sortimage1?></TH>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"'
ONMOUSEOUT='style.background="#B3B8A5"'><font face="verdana,arial" size=-1 ><a
href="ghacarrental.php?<?=$query2?>">State</a></font><?=$sortimage2?></TH>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"'ONMOUSEOUT='style.background="#B3B8A5"'><font
face="verdana,arial" size=-1><a href="ghacarrental.php?<?=$query3?>">City</a></font><?=$sortimage3?></TH>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"'ONMOUSEOUT='style.background="#B3B8A5"'><font
face="verdana,arial" size=-1><a href="ghacarrental.php?<?=$query4?>">Type</a></font><?=$sortimage4?></TH>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"' ONMOUSEOUT='style.background="#B3B8A5"'><font
face="verdana,arial" size=-1><a href="ghacarrental.php?<?=$query5?>">Supplier</a></font><?=$sortimage5?></TH>
<TH BGCOLOR="#B3B8A5" ONMOUSEOVER='style.background="#6B6C56"' ONMOUSEOUT='style.background="#B3B8A5"'><font
face="verdana,arial" size=-1>Remarks</font></TH>
<? echo "<TR>";
for($i = 0; $i < $numofrows; $i++)
{
$row = mysql_fetch_array($sql);
if($i % 2)
echo $formating ="<td bgcolor=\"#F7F0F4\" onMouseover=\"this.style.backgroundColor='#bfcdee';\"onMouseout=\"this.style.backgroundColor='#F7F0F4';\"><p align=\"LEFT\">";
else
echo $formating ="<td bgcolor=\"#FFFFCC\" onMouseover=\"this.style.backgroundColor='#CCFFFF';\"onMouseout=\"this.style.backgroundColor='#FFFFCC';\"><p align=\"LEFT\"> ";
echo $formating.$row['Code']."</TD>";
echo $formating.$row['State']."</TD>";
echo $formating.$row['City']."</TD>";
echo $formating.$row['Type']."</TD>";
echo $formating.$row['Supplier']."</TD>";
echo $formating.$row['Remarks']."</TD>";
echo "</TR>";
}
echo "<TR><td colspan=\"11\"><hr></hr></td></tr>";
echo "</tbody>";
echo "</table>";Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]