Current location: Hot Scripts Forums » Programming Languages » PHP » Query on url


Query on url

Reply
  #1 (permalink)  
Old 01-03-04, 12:44 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Query on url

Hi,

I'm using this script in order to get a set of results. But I would like to know to use the ? function in order top get results. i.e

http://www.selectguestlist.com/index/sunday.php?sort=id

or

http://www.selectguestlist.com/index....php?sort=name

I know this can be done with this type pf query:

SELECT * FROM `sunday` ORDER BY `name` ASC LIMIT 0, 30'

but how do you set it so I can start making url type query outputs?






<?
$link = mysql_connect('localhost',user', 'password')
or die("Could not connect");
mysql_select_db('select_db')
or die("Could not select database");
?>

<?

$query = 'SELECT * FROM `sunday` ORDER BY `name` ASC LIMIT 0, 30';
$page_result = mysql_query("select * from pageinfo where page like '$serial'");

$result=mysql_query($query)
or die(mysql_error());
?>



echo "<table>";
while ($row=mysql_fetch_object($result))
{
echo "<BODY bgColor=#155271 leftMargin=0 topMargin=0 rightMargin=0 bottomMargin=0 marginwidth=0 marginheight=0 onLoad=MM_preloadImages('guestlistOver.jpg','mapOv er.jpg','galleryOver.jpg')>";
echo "<TABLE cellSpacing=0 cellPadding=0 width=400 border=0>";
echo "<TBODY>";
echo "<TR>";
echo "<TD colSpan=2 height=6></TD></TR>";
echo "<TR>";
echo "<TD width=114 height=72><img height=73 src=clubs/$row->thumb width=109 border=0></TD>";
echo "<TD rowspan=5 vAlign=top> <TABLE width=100% height=134 border=0 cellPadding=0 cellSpacing=0>";
echo "<TBODY>";
echo "<TR>";
echo "<TD width=6><IMG height=8 src=home/bdr_leftcr.gif width=6 border=0></TD>";
echo "<TD width=100% background=home/bdr_top.gif height=6></TD>";
echo "<TD width=6><IMG height=8 src=home/bdr_rightcr.gif width=6 border=0></TD></TR>";
echo "<TR>";
echo "<TD width=6 height=128 background=home/bdr_rightside.gif>";
echo "<IMG height=128 src=home/bdr_leftside.gif width=6 border=0></TD>";
echo "<TD width=100% vAlign=top bgColor=#0F364A class=mainText>";
echo "<span class=mainTextBig>$row->name<br>$row->address</span>";
echo "<br>";
echo "<span class=mainText><br>$row->description<br>";
echo "<br><br>$row->info</span></TD>";
echo "<TD width=6 background=home/bdr_rightside.gif>";
echo "<IMG height=128 src=home/bdr_rightside.gif width=6 border=0></TD>";
echo "</TR>";
echo "</TBODY>";
echo "</TABLE>";
echo "<TABLE width=100% border=0 align=left cellPadding=0 cellSpacing=0>";
echo "<TBODY>";
echo "<TR>";
echo "<TD width=6><IMG height=20 src=home/bdr_leftcr_bt2.gif width=6 border=0></TD>";
echo "<TD height=20 background=home/bdr_bottom.gif>&nbsp;</TD>";
echo "<TD width=6><IMG height=20 src=home/bdr_rightcr_bt2.gif width=6 border=0></TD></TR>";
echo "</TBODY>";
echo "</TABLE></TD></TR>";
echo "<TR>";
echo "<TD height=20><img src=rate/$row->rate width=109 height=20></TD></TR>";
echo "<TR>";
echo "<TD height=20><a href=guestlist/sunday.htm target=_self onMouseOver=MM_swapImage('Guestlist1211','','guest listOver.jpg',1) onMouseOut=MM_swapImgRestore()><img src=guestlist.jpg alt=Guestlist name=Guestlist1211 width=109 height=20 border=0 id=Guestlist2></a></TD></TR>";
echo "<TR>";
echo "<TD height=20><a href=$row->map target=_blank onMouseOver=MM_swapImage('Map1211','','mapOver.jpg ',1) onMouseOut=MM_swapImgRestore()>";
echo "<img src=map.jpg alt=Map name=Map1211 width=109 height=20 border=0 id=Map2></a></TD></TR>";
echo "<TR>";
echo "<TD height=20><a href=$row->gallery onMouseOut=MM_swapImgRestore() onMouseOver=MM_swapImage('Gallery1211','','gallery Over.jpg',1)><img src=gallery.jpg alt=Gallery name=Gallery1211 width=109 height=20 border=0 id=Gallery2></a></TD></TR>";
echo "<TR>";
echo "<TD height=2></TD></TR>";
echo "</TBODY>";
}

echo "</TABLE>";

?>
Reply With Quote
  #2 (permalink)  
Old 01-03-04, 01:40 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
simply make your query like this :
PHP Code:

$sort=$_GET['sort'];

$info=mysql_query("SELECT * FROM sunday ORDER BY $sort ASC LIMIT 0, 30"); 
$_GET array fetches all the param coming from URL ...
like index.php?file=name&size=2 can get :
$_GET['file'] will equal 'name'
$_GET['size'] will equal '2'
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 01-03-04 at 01:53 PM.
Reply With Quote
  #3 (permalink)  
Old 01-03-04, 02:12 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the help

I used the following statement and used:


<?
$query = 'SELECT * FROM `sunday` ORDER BY `name` ASC LIMIT 0, 10';

$sort=$_GET['sort'];
$info=mysql_query("SELECT * FROM `sunday` ORDER BY '$sort' ASC LIMIT 0, 10");

$result=mysql_query($query)
or die(mysql_error());
?>


and

http://www.selectguestlist.com/index....php?sort=rate

to recall it but nothing happened, Am I doing it right? is the statment correct?

At the moment the query is on name order and would to like to call it in rate order.

Thanks for the help NeverMind
Reply With Quote
  #4 (permalink)  
Old 01-03-04, 03:01 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
errr according do your code..this is how it should be:
PHP Code:

$sort=$_GET['sort']; 

$query 'SELECT * FROM `sunday` ORDER BY $sort ASC LIMIT 0, 10';

$info=mysql_query("SELECT * FROM `sunday` ORDER BY '$sort' ASC LIMIT 0, 10"); // This is not used, should not be here.

$result=mysql_query($query)
or die(
mysql_error()); 
Reply With Quote
  #5 (permalink)  
Old 01-03-04, 03:13 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
I'm using the following :


PHP Code:

$sort=$_GET['sort']; 

$query 'SELECT * FROM `sunday` ORDER BY $sort ASC LIMIT 0, 10'

$result=mysql_query($query
or die(
mysql_error()); 

and its saying:


Unknown column '$sort' in 'order clause'

What should I be typing on the url to get it in rate order? Is it

http://www.selectguestlist.com/index....php?sort=rate

Thanks
Reply With Quote
  #6 (permalink)  
Old 01-03-04, 03:26 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
woops, my mistake
PHP Code:

$sort=$_GET['sort']; 

$query "SELECT * FROM sunday ORDER BY $sort ASC LIMIT 0, 10"

$result=mysql_query($query
or die(
mysql_error()); 
that should work

Last edited by Infinite_Hackers; 01-03-04 at 03:54 PM.
Reply With Quote
  #7 (permalink)  
Old 01-03-04, 03:46 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
No Luck

Says:
Parse error: parse error in /home/httpd/vhosts/selectguestlist.com/httpdocs/index/sunday2.php on line 49


then I tried it without the "**" and it said :

You have an error in your SQL syntax near 'ASC LIMIT 0, 10' at line 1
Reply With Quote
  #8 (permalink)  
Old 01-03-04, 03:50 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Full code

download here if you need to look at the whole thing, in normal working order


http://www.selectguestlist.com/index/sunday.txt

Last edited by dihan; 01-03-04 at 03:55 PM.
Reply With Quote
  #9 (permalink)  
Old 01-03-04, 03:58 PM
Infinite_Hackers's Avatar
Infinite_Hackers Infinite_Hackers is offline
Coding Addict
 
Join Date: Dec 2003
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
But you haven't changed it... (what **?)


Just replace this code:
<?
$sort=$_GET['sort'];
$query = 'SELECT * FROM `sunday` ORDER BY rate ASC LIMIT 0, 10';

$result=mysql_query($query)
or die(mysql_error());
?>


with this:
PHP Code:

<?

$sort
=$_GET['sort'];
$query "SELECT * FROM sunday ORDER BY $sort ASC LIMIT 0, 10"

$result=mysql_query($query)
or die(
mysql_error());
?>
Reply With Quote
  #10 (permalink)  
Old 01-03-04, 04:18 PM
dihan dihan is offline
Coding Addict
 
Join Date: Jan 2004
Posts: 267
Thanks: 0
Thanked 0 Times in 0 Posts
Thats great. Thanks dude. any idea why there is an error on page:

http://www.selectguestlist.com/index....php?sort=name

cant work it out


Thanks for all your help


09<?
10
11$link = mysql_connect('localhost','select_user', 'password')
12 or die("Could not connect");
13mysql_select_db('select_db')
14 or die("Could not select database");
15
16?>

Last edited by dihan; 01-03-04 at 04:30 PM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Declared Functions skipper23 PHP 4 12-17-03 10:06 AM
Trouble with query coolblu PHP 1 12-17-03 12:47 AM
index page not showing up skipper23 PHP 3 12-15-03 01:10 PM
Syntax error (missing operator) in query expression crobinson ASP 4 11-23-03 08:49 PM
Show query results by in a different way mdhall PHP 4 11-09-03 11:18 AM


All times are GMT -5. The time now is 07:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.