timprice Posted February 18, 2014 Share Posted February 18, 2014 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. Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/ 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); ?> Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469365 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']); Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469383 Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 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? Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469385 Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 nope that didnt work Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469386 Share on other sites More sharing options...
Ch0cu3r Posted February 18, 2014 Share Posted February 18, 2014 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/ Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469387 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 Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469389 Share on other sites More sharing options...
timprice Posted February 18, 2014 Author Share Posted February 18, 2014 Works with jquery.Thanks,*mark as closed* Link to comment https://forums.phpfreaks.com/topic/286281-simple-php-help/#findComment-1469400 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.