Page 1 of 1

View username problem

Posted: Thu Dec 15, 2011 10:43 am
by aquilina
I having a problem with viewing a username from another table.. i got 3 table in my database.. employee_user, employer_user and application table. my problem here is at application table..

Below is the code where employee applying the job

Code: Select all

[syntax=php]<div class="h3">Application</div>
<div class="mainbox">
<ul id="features">
<?php
if (isset($_SESSION['usernamejob']))
echo "<br />You already appplied for the job<br />";
else
    die ('You must be logged in!');
?>
<?php
$employer_id = $_GET['employer_id'];

if (isset($_SESSION['userid']))
$conn = mysql_connect("localhost","root","") or die ("Cannot connect!");
mysql_select_db("job_seeks") or die("cannot find the db");
$date = date("Y-m-d");
$query = mysql_query("SELECT * FROM application") or die(mysql_error());
$sql = 'INSERT INTO application (application_job_id, application_employee_id, date) VALUES ("'.$employer_id.'", "'.$_SESSION['employee_id'].'", "'.$date.'")';
$result = mysql_query($sql) or die(mysql_error());
?>
</ul>
</div>

[/syntax]

My problem here is i to view employee_user detail by using application_employee_id from application table. as a employer, they wanted to view whos apply for they job..

Below is code for employer_user to view employee_user that apply.. i stuck at this code btw..

Code: Select all

<div id="main">
<div class="h3">Check Application</div>
<div class="mainbox">
<?php

if (isset($_SESSION['employer_id']))
$con = mysql_connect("localhost","root","") or die (mysql_error());
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("job_seeks", $con);
$userid = $_GET['usernamejob'];
$result = mysql_query("SELECT * FROM application WHERE application_job_id=$userid");
while($row = mysql_fetch_array($result))
  {
  echo "<li><a href="."?page=job_detail".">".$row['application_job_id']."</a></li>";
  }
echo "</tbody>";
echo "</table>";

mysql_close($con);
?>
</div>
</div>

Re: View username problem

Posted: Thu Dec 15, 2011 11:31 am
by social_experiment
aquilina wrote:i stuck at this code btw..
Are you stuck with displaying the data from the table?

Re: View username problem

Posted: Thu Dec 15, 2011 11:36 am
by aquilina
yea i stuck displaying data of employee by using the application_employee_id in the application table

Re: View username problem

Posted: Thu Dec 15, 2011 12:17 pm
by aquilina
anyone can help? sorry i was beginner..

Re: View username problem

Posted: Thu Dec 15, 2011 12:33 pm
by social_experiment

Code: Select all

<?php echo "<li><a href="."?page=job_detail".">".$row['application_job_id']."</a></li>"; ?>
If this is your link that an employer will click to view details you will need to pass along a value that is unique to each record;

Code: Select all

<?php
 // create a link to the details page
 echo '<li><a href="detailPage.php?id=' . $row['application_job_id'] . '">' . $row['application_job_id'] . '</a></li>';
?>
On the page (detailPage.php in this instance) you will use $_GET['id'] to retrieve the value and then look for the corresponding record in the database

Code: Select all

<?php
 $id = $_GET['id'];
 // do some checking on the value you receive from the database
 $query = "SELECT * FROM yourTable WHERE field = '" . $id . "' ";
 $sql = mysql_query($query) or die(mysql_error());
 //
 if ($sql) {
  // if the query was executed successfully, we can start to select the data
  // from the database.
  while ($array = mysql_fetch_array($sql)) {
     // start to echo out the data
  }
 }
?>
This is a simple example; a look at your code shows you already have a basic grasp of database / PHP interaction.
Hth

Re: View username problem

Posted: Thu Dec 15, 2011 2:23 pm
by aquilina
i dont know how to display a data from employee table wheres application table got application_employee_id that connected with my employee table.. wheres my employee table have employee_id(employee table) that = application_employee_id(application table)... by using the application_employee_id from application table that got linked with employee_id from employee table, i wanted to display that data that inside employee table...

Re: View username problem

Posted: Fri Dec 16, 2011 12:34 am
by aquilina
solved