Displayiing page by ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Displayiing page by ID

Post 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'];
			}
?>
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post 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'";
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post 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']; 
    ..........
}
User avatar
psurrena
Forum Contributor
Posts: 355
Joined: Thu Nov 10, 2005 12:31 pm
Location: Broolyn, NY

Post by psurrena »

I removed the WHILE statement and now it works perfectly. Thanks!
Post Reply