query string problem :urgent

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
deeppak
Forum Commoner
Posts: 27
Joined: Thu Apr 06, 2006 6:31 am

query string problem :urgent

Post by deeppak »

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 = '&nbsp;&nbsp;<img src="../images/sort_dn_1.gif"></img>';
				
			}
			elseif($_REQUEST['fn']=='code' && $_REQUEST['sort']==' desc'){
				$sortimage1= '&nbsp;&nbsp;<img src="../images/sort_up_1.gif"></img>';
				}
			$sortimage2='';
			if ($_REQUEST['fn']=='state' && $_REQUEST['sort']==' asc') {
				$sortimage2 = '&nbsp;&nbsp;<img src="../images/sort_dn_1.gif"></img>';
			}
			elseif($_REQUEST['fn']=='state' && $_REQUEST['sort']==' desc') {
				$sortimage2='&nbsp;&nbsp;<img src="../images/sort_up_1.gif"></img>';
				}
			$sortimage3='';
			if ($_REQUEST['fn']=='city' && $_REQUEST['sort']==' asc') {
				$sortimage3 = '&nbsp;&nbsp;<img src="../images/sort_dn_1.gif"></img>';
			}
			elseif($_REQUEST['fn']=='city' && $_REQUEST['sort']==' desc'){
				$sortimage3='&nbsp;&nbsp;<img src="../images/sort_up_1.gif"></img>';
				}
			$sortimage4 = '';
			if ($_REQUEST['fn']=='type' && $_REQUEST['sort']==' asc') {
				$sortimage4 = '&nbsp;&nbsp;<img src="../images/sort_dn_1.gif"></img>';
			}
			elseif($_REQUEST['fn']=='type' && $_REQUEST['sort']==' desc') {
				$sortimage4 = '&nbsp;&nbsp;<img src="../images/sort_up_1.gif"></img>';
				}
			$sortimage5 = "";
			if ($_REQUEST['fn']=='supplier' && $_REQUEST['sort']==' asc'){
				$sortimage5 = '&nbsp;&nbsp;<img src="../images/sort_dn_1.gif"></img>';
			} elseif($_REQUEST['fn']=='supplier' && $_REQUEST['sort']==' desc') {
 				$sortimage5 = '&nbsp;&nbsp;<img src="../images/sort_up_1.gif"></img>';
			}
			?>
<TABLE WIDTH="80%" ALIGN="CENTER" BORDER="0" CELLPADDING="3" CELLSPACING="1">
			
<th>&nbsp;</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>";
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]
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:1. Select the correct board for your query. Take some time to read the guidelines in the sticky topic.
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:3. Do not make multiple, identical posts. This is viewed as spam and will be deleted.
User avatar
deeppak
Forum Commoner
Posts: 27
Joined: Thu Apr 06, 2006 6:31 am

Quey string

Post by deeppak »

I am sorry for this since i am new to yhe forum i commited this mistake kindly forgive me but the answer to my query is urgent so kindly provide me with the solution:

the place in the code where i need the help goes here

i am using perl to send the query string wih the following syntax:

$query->param(-name=>'sort',-value=>$sort);


i want to do the same in PHP can anyone plz provide me with the solution

i dont want to send it thorugh the page href element :

eg:

http://devnetwork.net?field=any

i want to send the query string which provides the same functionality as i was doing in perl as explained above

thanx
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

hi,
try this link...
http://codewalkers.com/tutorials/21/1.html

u may have some help from it
User avatar
deeppak
Forum Commoner
Posts: 27
Joined: Thu Apr 06, 2006 6:31 am

thanx

Post by deeppak »

thanx for the solution i met what was desired now my problem is solved

thanking u again
jito
Forum Commoner
Posts: 85
Joined: Sat Mar 25, 2006 4:32 am
Location: india

Post by jito »

that's good. happy coding.
Post Reply