...

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



kaihou
08-23-2006, 03: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.


<?php

$hostname='localhost';
$user='hello';
$pass= 'world';
$dbase='yay';

$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))
{
$id=$row["id"];
$title=$row["title"];
$icon=$row["icon"];
$layoutid=$row["layoutid"];
$dateadded=$row["dateadded"];
$series=$row["series"];
$layouttype=$row["layouttype"];
$email=$row["email"];
$name=$row["name"];
$indexurl=$row["indexurl"];
$downloadurl=$row["downloadurl"];
?>

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

<html>
<head>
<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">
</head>

<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"; ?>">
</frameset>
<noframes></noframes>

</html>
<?php
} #end of while

?>

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

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

JJ0117
08-23-2006, 05:13 PM
try this...

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

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

kaihou
08-27-2006, 12: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?

cubsfan
08-28-2006, 04: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))
{
etc.


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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum