Forum Moderators: coopster

Message Too Old, No Replies

Page contents based on url id

         

ajs83

4:34 am on Mar 5, 2005 (gmt 0)

10+ Year Member



I want to be able to make a url such as

[example.com...]

and have it the display the items from the table with with the id that is number 1. How would I do that?

Example

Table

id...name...image....date
1....test...g.jpg....01/01/05
2....teser..e.jpg....12/01/05

and when your go to

[example.com...]

It opens up the db and table so that it displays

test g.jpg 01/01/05

if you go to

[example.com...]

it displays

tester e.jpg 12/01/05

dreamcatcher

10:19 am on Mar 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

[example.com...]

To reference the id on your item.php page, use the following:

$id = $_GET['id'];

Then your query would be something like:

$query = mysql_query("SELECT * FROM table WHERE id = '$id' LIMIT 1") or die(mysql_error());

Then use one of the fetch methods to display your data, ie: mysql_fetch_row, mysql_fetch_object, mysql_fetch_assoc etc etc

An example using mysql_fetch_object would be:

$row = mysql_fetch_object($query);

echo $row->name . " " . $row->image . " " . $row->date;

Hope that helps.

dc

ajs83

7:59 am on Mar 21, 2005 (gmt 0)

10+ Year Member



Another question...

How would I set it up where if they visit item.php directly (without the?id=x) it tells them they have to select a title or redirect them to another page?

dreamcatcher

8:37 am on Mar 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$id = $_GET['id'];

if (empty($id))
{
header("Location: [yoursite.com");...]
}

The header function must be used before any other data is sent to the browser. If you don`t want to use this, then a few echo commands will do:

if (empty($id))
{
echo "Oops! This page is invalid\n";
echo "Please choose a link:<br><br>\n";
echo "<a href=\"page.php\">Page</a>\n";
exit;
}

exit terminates execution.

Hope that helps.

dc

ajs83

3:53 am on Mar 25, 2005 (gmt 0)

10+ Year Member



One more :)

Is it possible for me to add on to the url?

[example.com...]

?

supermanjnk

4:02 am on Mar 25, 2005 (gmt 0)

10+ Year Member



[example.com...]

you can do an

if ($_GET['*']) {

}

for each where star = id, user, or offer. you can also do this
<?
$i = "1";
foreach ($_GET as ${'key' . $i} => ${'val' . $i}) {
$i++;
}
?>
$key1 will equal id and $val1 will equal 1
$key2 will equal user and $val2 will equal 12
$key 3 will equal offer and $val3 will equal 1

if you take out the $i = "1"; and $i++
and do this instead:
<?
foreach ($_GET as $key => $val) {

}
?>
then each one will equal key and val during it's pass so the first pass $key will be id, the second pass $key will be user, the third pass $key will be offer