Jump to content

Recommended Posts

Hello all, i was wondering whether somebody could help me with a problem that i am having with my client contact web app. I am fairly new to php;

 

and what i am trying to do is  when a user clicks on the row of the table that displays all the jobs from the job table it opens up the profile-page for the selected job with all its details showing.

 

I know i need to get the [id] from the table but i am unaware how to do this ...

 

Any help would be greatly appreciated  :)

C¬Rose

 

<?

if ($log_in = true){
$db_name = "";
$table_name = "job";
$connection = @mysql_connect("localhost", "", "") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name";

$result = @mysql_query($sql) or die(mysql_error());


$numberofrows=mysql_num_rows($result);

$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php');" ;


echo'

<div id="rounded-corner">
		<p class="title">View Jobs</p>
			<table class="jobs">
				<tr>
					<th ><a class="table_header" >Job ID</a></th>
					<th ><a class="table_header" >Job Name</a></th>
					<th ><a class="table_header" >Company Name</a></th>
					<th ><a class="table_header" >Comapny ID</a></th>
					<th ><a class="table_header" >Job  Status</a></th>						
					<th ><a class="table_header" >% Complete</a></th>
					<th ><a class="table_header" >Contractor</a></th>

</tr>';


				while ($row = mysql_fetch_array($result)) 
		{		
			echo'	<tr>
						<td class="table_results" id="' . $row['job_id'] . '" onclick=' . $LOADcreateJOB1 . '>' . $row['job_id'] . '</td>
						<td class="table_results" href="index.php">' . $row['job_name'] . '</td>
						<td class="table_results">' . $row['company_name'] . '</td>
						<td class="table_results">' . $row['company_id'] . '</td>
						<td class="table_results">' . $row['job_status'] . '</td>
						<td class="table_results">' . $row['pcnt_complete'] . '</td>
						<td class="table_results">' . $row['contractor'] . '</td>

						</tr>
					</div>';


}
		}
?>

<? echo'<html>
<head>
<link href="forms_css.css" rel="stylesheet" type="text/css"  />
	<script type="text/javascript" src="jquery.js"></script>
<link href="style.css" rel="stylesheet" type="text/css"  />

</head>
<body>
</body>
</html>';
?>

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/
Share on other sites

Hey thanks for the reply,

I have tried a script to display the information from the table and it does not display the [] just the text? Could you tell me where i am going wrong with this

Cheers

C¬Rose

 

<?

echo'THIS IS THE JOB PROFILE PAGE';

if ($log_in = true){
$db_name = "";
$table_name = "job";
$connection = @mysql_connect("localhost", "root", "") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE FK_company_id = '$row[company_id]'";

$result = @mysql_query($sql) or die(mysql_error());

$data=mysql_fetch_array($result);

echo'<P>JOB ID:</P>'; $data['job_id'];
echo'<P> JOB NAME:</P>'; $data['job_name'];

echo'<P>COMPANY NAME:</P>'; $data['company_name'];
echo'<P> COMPANY ID:</P>'; $data['company_id'];

echo'<P> CONTACT FORENAME:</P>'; $data['contact_fname'];
echo'<P> CONTACT SURNAME:</P>'; $data['contact_sname'];
echo'<P> JOB STATUS:</P>'; $data['job_status'];
echo'<P> COMPLETE PERCENTAGE:</P>'; $data['pcnt_complete'];
echo'<P> CONTRACTOR:</P>'; $data['contractor'];
}	
?>

echo'<P>JOB ID:</P>' . $data['job_id'];
echo'<P> JOB NAME:</P>' . $data['job_name'];

 

You had a semi-colon after the echo statement, instead use a period for concatenation and it should work for you.

This is true of all of them... you need to combine the strings using a dot, not a semicolen. But you will need to end those lines with a semi colen. Use the example from cobalt-rose

Thanks for the replies, i have tried to use the method that you both instructed and keep getting a parse error at line 17... im guessing its the quotes and how i have set them?

 

<?

echo'THIS IS THE JOB PROFILE PAGE';

if ($log_in = true){
$db_name = "";
$table_name = "job";
$connection = @mysql_connect("localhost", "", "") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE FK_company_id = '$row[company_id]'";

$result = @mysql_query($sql) or die(mysql_error());


$data=mysql_fetch_array($result)

echo'<P>JOB ID:</P>' . $data['job_id'] . '</P>
<P> JOB NAME:</P>' . $data['job_name'] . '</P>

<P>COMPANY NAME:</P>' . $data['company_name']'</P>
<P> COMPANY ID:</P>' . $data['company_id']'</P>

<P> CONTACT FORENAME:</P>' . $data['contact_fname']'</P>
<P> CONTACT SURNAME:</P>' . $data['contact_sname']'</P>
<P> JOB STATUS:</P>' . $data['job_status']'</P>
<P> COMPLETE PERCENTAGE:</P>' . $data['pcnt_complete']'</P>
<P> CONTRACTOR:</P>' . $data['contractor'] . '</P> ';
}


?>

Hey sorry i posted redundant code i have already added the 'second period' and it still did not work.

 

I'm trying to get the job_id from the previous page  which is a table: of jobs:

BELOW: table with jobs from db


<?

if ($log_in = true){
$db_name = "";
$table_name = "job";
$connection = @mysql_connect("localhost", "", "") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name";

$result = @mysql_query($sql) or die(mysql_error());


$numberofrows=mysql_num_rows($result);

$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php');" ;


echo'

<div id="rounded-corner">
		<p class="title">View Jobs</p>
			<table class="jobs">
				<tr>
	<th ><a class="table_header" >Job ID</a></th>
	<th ><a class="table_header" >Job Name</a></th>
	<th ><a class="table_header" >Company Name</a></th>
	<th ><a class="table_header" >Comapny ID</a></th>
	<th ><a class="table_header" >Job  Status</a></th>						
	<th ><a class="table_header" >% Complete</a></th>
	<th ><a class="table_header" >Contractor</a></th>

</tr>';


			while ($row = mysql_fetch_array($result)) 
		{		
			echo'	<tr>
	<td class="table_results" id="' . $row['job_id'] . '" onclick=' . $LOADcreateJOB1 . '>' . $row['job_id'] . '</td>
	<td class="table_results" href="index.php">' . $row['job_name'] . '</td>
	<td class="table_results">' . $row['FK_company_id'] . '</td>
	<td class="table_results">' . $row['FK_company_id'] . '</td>
	<td class="table_results">' . $row['job_status'] . '</td>
	<td class="table_results">' . $row['pcnt_complete'] . '</td>
	<td class="table_results">' . $row['FK_contractor_id'] . '</td>
</tr>
	</div>';
}
		}
?>

<? echo'<html>
<head>
<link href="forms_css.css" rel="stylesheet" type="text/css"  />
	<script type="text/javascript" src="jquery.js"></script>
<link href="style.css" rel="stylesheet" type="text/css"  />

</head>
<body>
</body>
</html>';
?>

 

And then when a row is clicked on it opens up the "job profile page"

 

but currently i am only getting data displayed into the profile when i click on the first row of data but when i click on any other row i still get just the first row that it put into the profile??

 

Do i need to put the data into an array [0] on the PAGE ABOVE?

 

Below is my job profile page code which should show data collected form the row that was clicked on previously:

 

<?


echo'THIS IS THE JOB PROFILE PAGE';

if ($log_in = true){

$db_name = "";
$table_name = "job";
$connection = @mysql_connect("localhost", "", "") or die(mysql_error());
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT * FROM $table_name WHERE job_id = [job_id]";

$result = @mysql_query($sql) or die(mysql_error());

echo'$GET_[job_id]';

while ($data=mysql_fetch_array($result)) {

echo'<P>JOB ID:' . $data['job_id'] . '</P>
<P> JOB NAME:' . $data['job_name'] . '</P>

<P>COMPANY NAME:' . $data['company_name'] . '</P>
<P> COMPANY ID:' . $data['company_id'] . '</P>

<P> CONTACT FORENAME:</P>' . $data['contact_fname'] . '</P>
<P> CONTACT SURNAME:</P>' . $data['contact_sname'] . '</P>
<P> JOB STATUS:</P>' . $data['job_status'] . '</P>
<P> COMPLETE PERCENTAGE:</P>' . $data['pcnt_complete'] . '</P>
<P> CONTRACTOR:</P>' . $data['contractor'] . '</P> ';
}

}
?>




<html>
<head>
</head>
<body>

P

</body>
</html>

 

Hope this helps you understand at what ii am trying to do

 

Thank you for your time given so far,

very much appreciated

C¬Rose

i still don't see how it is that you are passing the 'id' value to the db query .. please be more clear (if you haven't already), as to how you are doing this.

 

if each outputted value doesn't have an id value to pass along once it's clicked, the query will just return the first row regardless of will link/button is clicked.

 

you must be passing a unique value to output unique records.

That's the thing... it isn't passing and i am only getting the first row...

 

I thought that as i put in the view jobs page

<td class="table_results" id="' . $row['job_id'] . '" onclick=' . $LOADcreateJOB1 . '>' . $row['job_id'] . '</td>

Which i thought would set the id of the table row to the id of the [job_id] that was pulled from the database then, i would be able to call the [job_id] on the profile page and select all the data where job_id(row from db) is equal to the [job_id] and display in the job profile page.

 

This obviously isn't working so how would you suggest i go about it?

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.