Reply
What does .php?id= mean?
Old 10-28-2009, 09:47 PM What does .php?id= mean?
WebTraffic's Avatar
Extreme Talker

Posts: 215
Name: Brandon
Trades: 0
I have always wondered how to use php to recall a specific article. On a lot of pages you see .php?id=3 or .php?article=Article-Name-Here and I am just curious as to how to use this.

Does this tell the php script to look in the database for the id table then go to record #3? Or does it tell the script to look within a certain table that has an id field with a record of 3?
__________________
Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 10-28-2009, 10:22 PM Re: What does .php?id= mean?
treyk4's Avatar
Skilled Talker

Posts: 80
Name: Trey
Trades: 0
It's much simpler than that. Anything after a ? that you see in the URL is where variables that are passed to a server-side PHP (or Perl, or ASP, etc.) script. Variables in the URL are called GET variables. The two ways to pass variables to a server-side script, like PHP, are through POST and GET.

Variables in the URL (GET variables) are separated by &. So, if the URL was something like:

http://www.example.com/page.php?foo=hello&bar=world

This would pass the two variables foo and bar to the server-side script page.php, where foo would be equal to hello and bar would be equal to world.

So, to answer your question, they would use a GET variable such as id to pass a number or word to the server telling it what page to display.

I've used this on a site I built, go to http://darcrobotics.org/index.php?p=about and you will see that its content is different than if you go to a page with a different variable, for example http://darcrobotics.org/index.php?p=home

There's a tutorial on POST and GET variables in PHP here: http://www.tizag.com/phpT/postget.php

Hope this helps!
~Trey
__________________
Decatur-Austin Robotics Coalition (DARC) - http://darcrobotics.org

Last edited by treyk4; 10-28-2009 at 10:23 PM..
treyk4 is offline
Reply With Quote
View Public Profile
 
Old 11-02-2009, 11:35 PM Re: What does .php?id= mean?
rednimaT's Avatar
Skilled Talker

Posts: 65
Name: Taminder B.
Location: San Jose, CA
Trades: 0
its your input to your script (input for id, can be anything the script specifies, id just means the script requires input id).
__________________
NRG Lab - Web Design Services & Resources
(HTML/PHP/MySQL/JavaScript/AJAX/SEO)
rednimaT is offline
Reply With Quote
View Public Profile Visit rednimaT's homepage!
 
Old 11-04-2009, 03:07 PM Re: What does .php?id= mean?
WebTraffic's Avatar
Extreme Talker

Posts: 215
Name: Brandon
Trades: 0
My primary key in my database is id for the products table (as it is with all of my tables.) The id field is auto-increment so that each product has a unique id.

Here is my products table showing 4 different fields (there are a total of 16 fields total in this table)

http://ingramswaterandair.com/db_testing/

As you can see, each product has its own id. if I wanted to view the information for say the product with the id 9, how would I go about doing this?

It is a simple question, but I'm guessing it is a complex answer. Adding index.php?id=9 to the end of the url just refreshes the page.

I would like to create a page that had the products listed on them, then when you click on the link it would show the product.

EDIT: This would make it much easier, as if I had a page with 2747 products on it, I could just make the url "index.php?id=".$row={'id'} to display the correct image.
__________________
Coding is just like a woman. If you don't do something exactly right, it complains.

Last edited by WebTraffic; 11-04-2009 at 03:13 PM..
WebTraffic is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 03:16 PM Re: What does .php?id= mean?
orionoreo's Avatar
Ultra Talker

Posts: 261
Name: Jerry
Trades: 0
you can use index.php or you can create a page called product.php you'll need a db connection first then you can do this

PHP Code:
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
    
$get_product "SELECT * FROM product_table WHERE id='$_GET[id]'";
    
    
$product mysql_fetch_assoc(mysql_query($get_product));
    
    echo 
$product['product_name'];
    echo 
$product['product_desc'];
} else {
    echo 
'Please Select Product';

orionoreo is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 03:16 PM Re: What does .php?id= mean?
Skilled Talker

Posts: 61
Name: John
Trades: 0
Simply modify your query based on GET:

PHP Code:
$dbSQL  "SELECT * FROM stuff";
$dbSQL .= !empty($_GET['id']) ? " WHERE id = ".$_GET['id'] : null
Then check your row count and act accordingly:

PHP Code:
if (mysql_num_rows($recordset_object) > 1)
 {
  
// ## show the product list
 
}
else
 {
  
// ## show the selected product
 


Last edited by Envision_frodo; 11-04-2009 at 03:21 PM..
Envision_frodo is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 03:34 PM Re: What does .php?id= mean?
WebTraffic's Avatar
Extreme Talker

Posts: 215
Name: Brandon
Trades: 0
Ah I understand now. Basically it is an if/else statement that says...

If there has not been a product selected then show the product list.

If there has been a product selected, then show the product information.

And this can only be accomplished with the GET method because it passes the variables through the URL.

Therefore if I added this code and there was only 1 returned value for ID (such as index.php?id=9) then it would show that product.

Then if I wanted to break it down even more for something like specifications on that product I could add another if/else statement and have the url be something like...

specifications.php?id=9 or something like this that would only display the specification information rather than the price and everything else.

I believe I understand now. I will try to get it working, if not I may be back to ask more questions.

Brandon
__________________
Coding is just like a woman. If you don't do something exactly right, it complains.

Last edited by WebTraffic; 11-04-2009 at 03:36 PM..
WebTraffic is offline
Reply With Quote
View Public Profile
 
Old 11-04-2009, 05:41 PM Re: What does .php?id= mean?
WebTraffic's Avatar
Extreme Talker

Posts: 215
Name: Brandon
Trades: 0
Thank you guys. I got this working. You can take a look at it at http://www.ingramswaterandair.com/db_testing

This is exactly what I was wanting to figure out.
__________________
Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to What does .php?id= mean?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.13457 seconds with 13 queries