Jump to content

sending mysql query results to another page by link


jobs1109

Recommended Posts

Hi,

 

I am trying to send mysql query to another page by link.  I would like users to be able to click

on a link from mysql query result and then be able to see more details on a second page for the row selected in the link. Here is an example of what I am trying to do.  http://www.jobberbase.com/demo/.  In my code when I go to second page it does not show the correct row of data when link is clicked. Here is my code .

 

 

first page with mysql query results.

 



<?php
session_start();
?>



// Post variables

<?php
$_SESSION['Keyword_Search']    = $_POST['Keyword_Search']; 
$_SESSION['Jobcategory']      = $_POST['Jobcategory'];
$Keyword_Search =  $_SESSION['Keyword_Search'];
$Jobcategory =  $_SESSION['Jobcategory'];
// echo $Keyword_Search; will be used in future
// echo $Jobcategory; will be used in future


include'../../DB-Connect101/DB-Connect101.php';


// getting data from table "Jobs-table"



$query = "SELECT * FROM Jobs-table"; 

$result = mysql_query("	SELECT 	 'id', `JobTitle`,	  `Company`,	  `Salary`,	  `Description`,	  `CompanyURL`,	  `PhoneNumber`,	  `Requirements`,	  `JobCategory`,	  `JobType`,	  `Apply_To`,	  `Email`,	  `State`,	  `Address`,	  `Country`,	  `Zipcode`	FROM	  `Jobs-table` ") or die(mysql_error());while ($row = mysql_fetch_array($result)) { 	echo 'Job Title: <a href="http://www.hiringinhilo.com/Hilo-Jobs/Job-Search-Form/Getting-Data-From-Database/Job-Details/Job-Details.php">'.$row['JobTitle'].'</a><br /><br />';	}

?>




 

 

 

Here is the second page when results for selected row should be displayed.

 



<?php
session_start();
?>


<?php
include'../../../DB-Connect101/DB-Connect101.php';

$Keyword_Search =  $_SESSION['Keyword_Search'];
$Jobcategory =  $_SESSION['Jobcategory'];
// echo $Keyword_Search;
// echo $Jobcategory;


?>
<br>
<br>
<br>

<?php

$id = $_SESSION['id']; 
$query = "SELECT * FROM Jobs-table where id=$id"; 

$result = mysql_query("	SELECT 	`id`,  `JobTitle`,	  `Company`,	  `Salary`,	  `Description`,	  `CompanyURL`,	  `PhoneNumber`,	  `Requirements`,	  `JobCategory`,	  `JobType`,	  `Apply_To`,	  `Email`,	  `State`,	  `Address`,	  `Country`,	  `Zipcode`	FROM	  `Jobs-table` ORDER BY id ASC")
or die(mysql_error());
$row = mysql_fetch_array($result);


echo "ID: ".$row['id'];
echo "<br>Job Title: ".$row['JobTitle'];
echo "<br> Company: ".$row['Company'];
echo " <br>Salary: ".$row['Salary'];
echo "<br> Description: ".$row['Description'];
echo "<br> Company-URL: ".$row['CompanyURL'];
echo "<br> Phone-Number: ".$row['Phone-Number'];
echo "<br> Address: ".$row['Address'];
echo "<br> Requirements: ".$row['Requirements'];
echo "<br> Job-Type: ".$row['JobType'];
echo "<br> JobCategory: ".$row['JobCategory'];
echo "<br><br><br><br><br>";

?>







 

 

why is my code not working ? please help

Link to comment
Share on other sites

You want your url to look like this

 

http://www.hiringinhilo.com/Hilo-Jobs/Job-Search-Form/Getting-Data-From-Database/Job-Details/Job-Details.php?id=$row['id']

 

Then on the display page, get that ID number using $_GET['id']

 

On another note, you should only select columns from your database that you plan on using. You can shorten your initial query to

"SELECT `id`, `JobTitle` FROM `Jobs-table`"

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.