cobalt-rose Posted March 31, 2009 Share Posted March 31, 2009 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>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/ Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 is the field called 'id'? By using * in the select statement, you've grabbed all of the fields and you should be able to use the 'id' field with $row['id'] Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797796 Share on other sites More sharing options...
cobalt-rose Posted March 31, 2009 Author Share Posted March 31, 2009 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']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797879 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797885 Share on other sites More sharing options...
Brian W Posted March 31, 2009 Share Posted March 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797894 Share on other sites More sharing options...
cobalt-rose Posted March 31, 2009 Author Share Posted March 31, 2009 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> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797932 Share on other sites More sharing options...
premiso Posted March 31, 2009 Share Posted March 31, 2009 You are missing the second period on everything after the job name. Make it look exactly like the job id and job name for each sequential line. Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-797937 Share on other sites More sharing options...
cobalt-rose Posted March 31, 2009 Author Share Posted March 31, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798020 Share on other sites More sharing options...
mrMarcus Posted March 31, 2009 Share Posted March 31, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798045 Share on other sites More sharing options...
cobalt-rose Posted March 31, 2009 Author Share Posted March 31, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798064 Share on other sites More sharing options...
cobalt-rose Posted April 1, 2009 Author Share Posted April 1, 2009 How can i get unique values into the data table? do i have to use an array? Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798497 Share on other sites More sharing options...
kev wood Posted April 1, 2009 Share Posted April 1, 2009 does your table have a column which has the title id and is set to auto increment. if you have then you are already giving each row a unique id and this should be used to display unique rows from the table. Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798501 Share on other sites More sharing options...
cobalt-rose Posted April 1, 2009 Author Share Posted April 1, 2009 Yes i do have a row that auto increments...so i do have a unique field Quote Link to comment https://forums.phpfreaks.com/topic/151928-need-help-in-getting-id-from-my-table/#findComment-798999 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.