View Full Version : How do I use $_GET to put a variable in the URL?

08-23-2006, 04:15 PM
Hi, I'm trying to make a preview/view page for my layout database using frames, php, and mysql. How can I make it so that the URL will be http://www.mysite.net/view.php?id=#, while the id # corresponds to the id of the layout/database row? This is what I have so far, without any $_GET variables or whatever.


$pass= 'world';

$connection = mysql_connect("$hostname" , "$user" , "$pass") or die ("Can't connect to MySQL");
$db = mysql_select_db($dbase , $connection) or die ("Can't select database.");

$q = "select * from newlayout";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<title>View Layout <?php echo "$layoutid"; ?> / <?php echo "$id"; ?> - <?php echo "$title"; ?> by <?php echo "$name"; ?></title>
<link rel="stylesheet" href="http://www.mysite.net/style.css" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<frameset rows="40,*" frameborder="0" >
<frame name="topFrame" scrolling="no" noresize src="http://www.mysite.net/viewtop.php" >
<frame name="mainFrame" src="<?php echo "$indexurl"; ?>">

} #end of while


$layoutid is a manual variable I made for the IDs... ignore it for now. So can anyone help? :confused:

08-23-2006, 05:48 PM
Which url do you want to append the id to?

08-23-2006, 06:13 PM
try this...

<link rel="stylesheet" href="http://www.mysite.net/style.css?id=<?php echo $id ?>" type="text/css">

08-24-2006, 05:30 AM
I have a problem like his. It's for my comic script. How the hell will adding a style sheet solve anything?

08-27-2006, 01:04 AM
Why a stylesheet? o.o

URL... to append to? What does that mean? I want it so that when you go to view.php?id=# it will show the all the info I want that goes with the ID. The ID is the primary key, so it only needs the ID, correct?

08-28-2006, 05:42 PM
In that case then you will want to do something like this.

$q = "select * from newlayout where id='" . $_GET['id'] . "'";
$result= mysql_query($q, $connection) or die
("Could not execute query : $q." . mysql_error());

while ($row=mysql_fetch_array($result))

Just use the ID from the get variable to define your query.

08-31-2006, 07:36 PM
^_^ Thanks!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum