Log in

View Full Version : PHP ID tags???



Rockonmetal
09-22-2007, 05:03 PM
Ok, I keep seeing these and I want to know how to make these...
Like on some sites where they have multiple products they have a link and in the bottom it says:

http://www.site.com/items?id=38324
How do I get it so I can do something like that???

Sorry to be so vague but I really don't know how to do this or what exactly it is but its cool...

thetestingsite
09-22-2007, 05:11 PM
All that the id part of the url you listed above is just a simple GET variable. In other words, you would do something like this to get the value of what is submitted in the url:



<?php
$id = $_GET['id']; //will assign the value of 38324 for the url listed above.

/* After getting the above variable, you can use that to identify the id of a certain database entry, or a file, or whatnot. */
?>


Hope this helps.

Rockonmetal
09-22-2007, 05:17 PM
k... I thought it was something like that... Let me get this straight...

would it be something like this:

<?php
$id = $_GET['id'];
if($id==2){
include("file1.php");
}else{
include("index.php");
}
?>



I don't think its that...

but if i wanted to do it via database how would I go about doing that?

thetestingsite
09-22-2007, 05:26 PM
would it be something like this:

<?php
$id = $_GET['id'];
if($id==2){
include("file1.php");
}else{
include("index.php");
}
?>



You could do it that way, because "id" could be anything else; such as: text, testing, ids, something, blah, etc. Being that it is just a variable, the possibilities are endless.



if i wanted to do it via database how would I go about doing that?

Step 1: Set up your database to your liking and to suit your need.
Step 2: Set up the php script to connect to the database.
Step 3: Use the unique identifier as a way to get the data you want to extract.
Step 4: Set up the script to pull up those entries.

So this would be something like the following for example:

list.php


<?php
include('dbconnect.php'); //all of your database connection stuff

if (isset($_GET['id'])) {
$getItem = mysql_query("SELECT * FROM `table` WHERE `id`='" . $_GET['id'] . "'");

while ($q = mysql_fetch_array($getItem)) {
echo $q['somecolumn']; //this will echo the column value that you specify
}
}

else { //if the id is not set, show all items in database
$the_list = mysql_query("SELECT * FROM `table`");

while ($q = mysql_fetch_array($the_list)) {
?>
<a href="?id=<?php echo $q['id'];?>">Click here for the item</a> | <?php echo $q['somecolumn'];?> <BR>
<?php
}
}
?>


Hope this helps.

Rockonmetal
09-22-2007, 05:28 PM
K thanks man... I'll try that as soon as I get mysql working...

djr33
09-22-2007, 07:50 PM
http://php-mysql-tutorial.com
go through that and a lot of your database questions should be cleared up.
mysql is not very hard, but it's not similar to other languages, so you'll need to get some experience before it starts making sense.

Twey
09-23-2007, 12:01 AM
If you're just starting with databases, there are other (better) solutions available like PostgreSQL.

tech_support
09-23-2007, 02:51 AM
If you're just starting with databases, there are other (better) solutions available like PostgreSQL.
How is it better than MySQL(i)?

Twey
09-23-2007, 11:18 AM
It adheres to the SQL standard a lot better, as well as having arguably better performance.