How to get id from my table

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
whizzkid-000
Forum Newbie
Posts: 8
Joined: Mon Jul 09, 2007 5:36 pm

How to get id from my table

Post by whizzkid-000 »

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 job-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 ...

I don't think its possible to use the GET method as i am loading the job-profile-page into a div using Js please correct me if i am wrong.

Any help would be greatly appreciated :)
C¬Rose

Code: Select all

 
<?
        
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>';
?>
dead leprachorn
Forum Newbie
Posts: 6
Joined: Tue Mar 31, 2009 10:08 am

Re: How to get id from my table

Post by dead leprachorn »

I don't think its possible to use the GET method as i am loading the job-profile-page into a div using Js please correct me if i am wrong.
You are wrong, consider this a correction :D
$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php');" ;
the url can be appended as normal to include GET data.

Code: Select all

$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php?key1=val1&etc');" ;
you could also try looking at the jquery site.
http://docs.jquery.com/Category:Ajax
whizzkid-000
Forum Newbie
Posts: 8
Joined: Mon Jul 09, 2007 5:36 pm

Re: How to get id from my table

Post by whizzkid-000 »

$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php');" ;
the url can be appended as normal to include GET data.

Code: Select all

$LOADcreateJOB1 = "$('#page_contents').load('profile_job.php?key1=val1&etc');" ;
you could also try looking at the jquery site.
http://docs.jquery.com/Category:Ajax[/quote]

Hey thanks for the reply... :)

I have tried doing what you said in passing the value through the url but still cannot get the variable [jid] onto the other page...
Even when i print it out it still shows nothing on PROFILE PAGE.

What i did notice was that when i just echod the ' . $row['job_id'] . ' on th VIEW JOBS page i got a list of results 9000 9001 90002 9003 9004 etc... does this mean that i have to use an array? to like be able to distinguish between the results that were displayed?

VIEW JOBS page:

Code: Select all

 
<?
        
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?jid=$var');" ;
 
$var = $row['job_id'];
 
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>
  ' . $row['job_id'] . '
                            </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>';
?>

JOB PROFILE page:

Code: Select all

<?
 
$job = $GET_['jid'];
$job;
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'; ";
 
$result = @mysql_query($sql) or die(mysql_error());
 
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>
    </body>
    </html>
Post Reply