Jump to content

Using ID's


idgeit

Recommended Posts

Hey all,

 

I've been trying to figure out how exactly to do this. At the moment I've got a php page that pulls up info from a database and displays it,

 

But I would like to make a single page and let the ID of the product change and then the page will change to suit the ID.

 

sort of like this page i.e

 

/index.php?=actionpost.......... ect

 

I have no idea where i should be looking under, or what even this is called.

 

Any help would be great,

 

Thanks!

 

~ Idgeitman

Link to comment
https://forums.phpfreaks.com/topic/39798-using-ids/
Share on other sites

It ends up getting used in everything day/day programming.

 

For a basic example, here is something off one of my projects, with the same idea.

 

<?php
// get user information based on stored session
$selectuser = "SELECT * FROM userinformation";
$queryuser = mysql_query($selectuser);
echo "<p>Below is all the information about current Clients.</p>";
echo "<hr />";
while ($rowuser = mysql_fetch_array($queryuser)) {
// if record found display there user information for editing
?>
<?php
// display admins here
echo "<b>Id:</b> " . stripslashes($rowuser['id']);
$edit = "<a href=\"editexistingclient.php?id={$rowuser[id]}\" title=\"Edit This Client\">Edit</a>";
$delete = "<a href=\"deleteclient.php?id={$rowuser[id]}\" title=\"Delete This Client\">Delete</a>";

$addproof = "<a href=\"addproof.php?id={$rowuser[id]}\" title=\"Add Proof\">Add Proof</a>";
$vieworeditproof = "<a href=\"vieworeditproof.php?id={$rowuser[id]}\" title=\"View or Edit Proof\">View or Edit Proof</a>";

echo "<br />";
echo "<b>Email:</b> " . stripslashes($rowuser['email']);
echo "<br />";
echo "<b>Username:</b> " . stripslashes($rowuser['username']);
echo "<br />";
echo $edit . " - " . $delete;
echo "<br />";
echo "<br />";
echo $addproof;
echo " - ";
echo $vieworeditproof;
echo "<hr />";
?>
<?php
}
?>

That pretty much pulls the list of clients, you see the id's getting passed to the various pages.  On those pages things happen with the data.  Like for adding  a proof (vice versa.

 

on the page you simply

 

$id = $_GET['id'];

clean it first however.  And there is your id, from there it's basic query knowledge and you can work up your queries, and do whatever you want with it.

Link to comment
https://forums.phpfreaks.com/topic/39798-using-ids/#findComment-192374
Share on other sites

i just came across one small problem, I can use echo and print the ID number, but what exactly should i do when I want to use it in a query?

 

$query = 'SELECT products.product_id, products.product_dis, products.product_price, products.product_title FROM products WHERE products.product_id = 10001';

 

That works fine for the id as 10001 but how can I replace it with the $_GET result?

 

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/39798-using-ids/#findComment-193891
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.