timprice Posted February 18, 2014 Share Posted February 18, 2014 (edited) Hi all,I am new to php, and just using some help guides to try and build a basic system.What I would like is an output page to display a table with selected data in (that I can do)I would how ever like the the table rows to be links to another page which contains more information of which ever row I clicked.eg:/output.php Job Ref | Client | Site | Description <------click this row of data to take you to the next page.output2.phpStart Date | Duration | Machines | Technicians <------- This page only shows the data taken from the row above.This is my code for the 1st page (output.php) Basic Code <html> <meta http-equiv="refresh" content="120"> </html> <?php $con=mysqli_connect("localhost","root","","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $result = mysqli_query($con,"SELECT * FROM table"); echo "<table border='1'> <tr> <th>Job Ref</th> <th>Client</th> <th>Site</th> <th>Job Description</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['jobref'] . "</td>"; echo "<td>" . $row['client'] . "</td>"; echo "<td>" . $row['site'] . "</td>"; echo "<td>" . $row['Job_description'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> Thanks for any help guys. Edited February 18, 2014 by timprice Quote Link to comment Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 I have been trying this but I dont think its is carrying over the row ID to the seconds page. while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['jobref'] }</a> </td>"; echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['client'] }</a> </td>"; echo "<td>" . $row['site'] . "</td>"; echo "<td>" . $row['Job_description'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> Secondpage <?php $con=mysqli_connect("localhost","root","","database"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $rowId=$_GET['id']; $result = mysqli_query($con,"SELECT * FROM table WHERE id=$rowId"); echo "<table border='1'> <tr> <th>Job Ref</th> <th>Client</th> <th>Site</th> <th>Job Description</th> </tr>"; while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['jobref'] . "</td>"; echo "<td>" . $row['client'] . "</td>"; echo "<td>" . $row['site'] . "</td>"; echo "<td>" . $row['Job_description'] . "</td>"; echo "</tr>"; } echo "</table>"; mysqli_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 18, 2014 Share Posted February 18, 2014 echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['jobref'] }</a> </td>"; echo "<td><a href=\"secondpage.php?id={$row['id']}\">{$row['client'] }</a> </td>"; That should pass the rows id to secondpage provided you do have a column called id in your database, which holds the records id. The code used in secondpage.php should work, however I'd use the following when getting the id $rowId=intval($_GET['id']); Quote Link to comment Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 (edited) Arrrrh, right yeah it was failing becuase 'id' was in caps in the database.Ok so thats working, but it makes each of those as hyperlinks to a new page which while in essence is fine, what I would like is for the whole row to be a link.Im not sure how to do that.Can I put that code say here: while($row = mysqli_fetch_array($result)) { echo "<tr><a href=\"secondpage.php?id={$row['id']}\">"; echo "<td>" . {$row['jobref'] }. "</td>"; echo "<td>" . {$row['client'] }. "</td>"; echo "<td>" . $row['site'] . "</td>"; echo "<td>" . $row['Job_description'] . "</td>"; echo "</a></tr>"; } echo "</table>"; mysqli_close($con); ?> To make the whole row a link not just the text? Edited February 18, 2014 by timprice Quote Link to comment Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 nope that didnt work Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted February 18, 2014 Share Posted February 18, 2014 (edited) HTML on its own doesn't allow whole rows to be linkable. Instead you'll need to use javascript to provide that functionality. Example with JQuery http://www.electrictoolbox.com/jquey-make-entire-table-row-clickable/ Edited February 18, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 Ok I will look into that. Thankyou Quote Link to comment Share on other sites More sharing options...
Solution timprice Posted February 18, 2014 Author Solution Share Posted February 18, 2014 Works with jquery.Thanks,*mark as closed* Quote Link to comment 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.