Page 1 of 1

Displayiing page by ID

Posted: Thu Apr 06, 2006 12:46 pm
by psurrena
My question is, I have two pages, one with a list of jobs and one to display the job information. The list of jobs page displays fine and creates a link (<a href="view.php?id= $id">view</a>). This puts the proper ID in the URL but how to I make the second page (view.php) realize the ID and display the information accordingly?

Thanks,
Pete

This is the code for view.php:

Code: Select all

<?php	

		mysql_connect ('host', 'user', 'pass') or die ('Error connecting to mysql');
		mysql_select_db (database);	
					
			$query   = "SELECT * FROM job WHERE id='id'";
			$result  = mysql_query($query) or die('Error : ' . mysql_error());  
			$row     = mysql_fetch_array($result, MYSQL_ASSOC); 
	
			while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
		
			$fname   = $row['fname'];
			$lname   = $row['lname'];
			$company = $row['company'];
			$jnum	 = $row['job_num'];
			$jname	 = $row['job_name'];
			$jdes	 = $row['job_des'];
			$jcost	 = $row['job_cost'];
			$jstart	 = $row['job_start'];
			$jend	 = $row['job_end'];
			}
?>

Posted: Thu Apr 06, 2006 12:54 pm
by hawleyjr
id is not a variable just a string...

Code: Select all

$query   = "SELECT * FROM job WHERE id='id'";

Code: Select all

$id = $_GET['id'];
//INSERT VALIDATION CHECKING HERE TO MAKE SURE ID IS AN INTEGER

$query   = "SELECT * FROM job WHERE id='$id'";

Posted: Thu Apr 06, 2006 1:03 pm
by psurrena
It does not return anything (nor does it error). How does $id = $_GET['id']; know where it's at?

The url states the ID but I don't understand how that's carried throughout.

The reason I'm asking is because I don't want use:

Code: Select all

if(!isset($_GET['id'])) { 
.........
} else {
    $query   = "SELECT * FROM port WHERE id=".$_GET['id']; 
    ..........
}

Posted: Thu Apr 06, 2006 1:17 pm
by psurrena
I removed the WHILE statement and now it works perfectly. Thanks!