Jump to content

dynamic link php and mysql


jobs1109

Recommended Posts

Hi Everyone,

 

I am trying to send a row of data to a page depending on which row is clicked Here is the code I have so far.

 




<?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;
// echo $Jobcategory;

?>


<?php
include'../../DB-connect-here/DB-connetingtodatabase.php';

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


?>
<br>
<br>
<br>

<?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` ORDER BY id ASC")
or die(mysql_error());while ($row = mysql_fetch_array($result)) 



{


<?php echo 'Title: <a href="Job-Details.php?id=<?php echo $row['id']; ?>">'.$row['JobTitle'].'</a><br />';

}?>



 

 

here is the error message I am getting

 

 

 

Parse error: syntax error, unexpected '<'Getting-Data-Database6.php on line 50

 

 

here is line 50

 

 

<?php echo 'Title: <a href="Job-Details.php?id=<?php echo $row['id']; ?>">'.$row['JobTitle'].'</a><br />';

 

 

What am I doing wrong ?

 

Thanks

DS

Link to comment
Share on other sites

few things here..

 

1. why do you define $Keyword_Search and $Jobcategory to the same values twice..?

2. Why do you define $query without using it..?

3. As the color code tells you, this is a concatenation issue.. change to

 

 <?php 
echo "Title: <a href=\"Job-Details.php?id=<?php echo {$row['id']}; ?>\">{$row['JobTitle']}</a><br />";

Link to comment
Share on other sites

if I echo out the id I get all the id numbers.

 



<?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` ORDER BY id ASC")
or die(mysql_error());while ($row = mysql_fetch_array($result)) 



{

echo "<br>Job ID: ".$row['id'];



}

?>




 

 

 

I get back

 

 

Job ID: 39

Job ID: 40

Job ID: 41

Job ID: 42

Job ID: 43

Link to comment
Share on other sites

here is the code I have now

 



<?php
session_start();
?>



// Post variables

<?php
include'../../DB-connection/DB-connect.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

?>



<br>
<br>
<br>

<?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` ORDER BY id ASC")
or die(mysql_error());while ($row = mysql_fetch_array($result)) 



{

<?php echo "Title: <a href=\"Job-Details.php?id=<?php echo {$row['id']}; ?>\">{$row['JobTitle']}</a><br />";



}

?>




 

 

if I echo 'title, Address, id etc I get back all the info but I am still getting the following error message

 

 

 

Parse error: syntax error, unexpected '<' in /Getting-Data-Database7.php on line 43

 

 

here is the line 43

<?php echo "Title: <a href=\"Job-Details.php?id=<?php echo {$row['id']}; ?>\">{$row['JobTitle']}</a><br />";

I would like users to click on the title and go to the "Job-Details.php" page where the details will be desplayed for the job id link clicked.

Link to comment
Share on other sites

Hi Thanks,

 

here is what I have on the details page

 

 

 



<?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>";

?>



 

 

now I get the same results for all the links.

Link to comment
Share on other sites

1. you are using backticks " ` " in your index when you should be using quotes... like this

 

$id = $_SESSION[`id`]; //wrong way
$id = $_SESSION['id']; //right way

 

2. If you are expecting more than one row to be grabbed from your query... place your code in a while loop..

 

while($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>";
}

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.