Reputation: 53
Hi programmers and web designers, I am working on a small system for the company I work with and everything is almost done (thanks for this site and the help from other sites...) except for this function where I want the entire row of the table my php codes generated, for now I was only able to make my second column clickable. I already tried googling but I can't find a workable solution. FYI, I am a noob and just starting to learn php.... thanks in advance...
while($info = mysql_fetch_array( $data ))
{ echo "<tr> class='tablerows' align=center onclick=\"window.location=http://active_jobs.php?job_ticket='".$info['job_ticket']."'\">
<td>".$info['date']."</td>;
<td><a> href=somefile.php?job_ticket=".$info['job_ticket'].">".$info['job_ticket']."</td>
<td>".$info['invoice_no']."</td> <td>".$info['customer']."</td>
<td>".$info['job_type']."</td> <td>".$info['complete_date']."</td>
<td>".$info['complete_time']."</td>
<td>".$info['artist_operator_prepress']."</td>
<td>".$info['status_prepress']."</td>
<td>".$info['status_press']."</td>
<td>".$info['status_postpress']."</td> <td
width='300'>".$info['remarks']."</td>"; echo "</tr>";
} echo
"</table>";
Thanks in advance for your help. Marco
Upvotes: 0
Views: 12346
Reputation: 1
Well, you can make a table row clickable. It is very easy. You just make invisible buttons inside each table sell. Make them without borders and no colors. Then, just handle the entire row as a clickable button. You will need to do this for each TD in the row. Also, you have to have a unique id for each row so that the button can identify the row number. Something loosely like this:
<td><button type='submit' name='click_row' value='" . $info["id"] . "' style='width: 100%; background: none; border: none; box-shadow: none;'>DATA FOR THIS TD</button></td>
Then, you need to process the buttons for the row. ( Same button for each TD in the row. ) Something loosely like this:
if (isset($_POST["click_row"])) {
$clicked_row = $_POST["click_row"];
// Handle what you want done with this row...
}
Works well for me!
Upvotes: 0
Reputation: 2819
For those kind of live edit in table values with php, you can go for client side scripting language javascript & jquery with ajax..
For Reference :
It's worthy...
Upvotes: 1
Reputation: 819
i am answering this question by assuming that you are aware of JQUERY.Written a sample code copy it into a file '.html' and run. make sure that you are connected to internet to let jquery api to load.Thanks.
ex:-
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('table tr').click( function () {
alert('i am clicked');
} );
});
</script>
</head>
<body>
<table border="1">
<tr><td>1</td><td>apple</td><td>boy</td><td>jjjj</td><td>dddd</td><td></td><td>1010</td><td>1019</td><td>06-Mar-13 21:47:34</td></tr>
<tr><td>2</td><td>strawberry</td><td>girl</td><td>jjjj</td><td>dddd</td><td></td><td>1010</td><td>1019</td><td>06-Mar-13 21:47:34</td></tr>
<tr><td>2</td><td>strawberry</td><td>girl</td><td>jjjj</td><td>dddd</td><td></td><td>1010</td><td>1019</td><td>06-Mar-13 21:47:34</td></tr>
</table>
</body>
</html>
Upvotes: 0
Reputation: 91742
You should check the generated html, you are closing the <tr>
tag so the class and javascript are no longer part of it:
{ echo "<tr> class='tablerows' align=center onclick=\"window.location=http://active_jobs.php?job_ticket='".$info['job_ticket']."'\">
^ remove this and check the html again; it probably works now
You have the same mistake on the fourth line with the a
tag.
Upvotes: 1
Reputation: 39399
You can’t make entire rows “clickable” using PHP. PHP is a server-side language; you generate HTML and spit it out.
If you wanted to make an entire table row clickable, you’d either have to wrap it in an <a>
(invalid HTML), or use a client-side language such as JavaScript to apply an event listener, that listens for the <tr>
being clicked and redirects to whatever URL you want.
Upvotes: 3