February 11, 201412 yr Hi I have started learning PHP and have managed to create a databse with entries. I have now got a page to display a table displaying only three fields from the DB, 'Name, Summary and Keywords. The other fields include 'OpportunityID' 'Experience' and 'Body' for example. My question is, how can I make the 'Name' title into a hyperlink to allow the user to then view the full content of the item. A sample of the code to display the table is echo "<table border='1'><tr><th>Name</th><th>Summary</th><th>Keywords</th></tr>";while($row = mysqli_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Name'] . "</td>"; echo "<td>" . $row['Summary'] . "</td>"; echo "<td>" . $row['Keywords'] . "</td>"; echo "</tr>"; }echo "</table>"; Don't forget I am just learning :-)
February 11, 201412 yr First to answer your query with a basic, but dirty method. The table row you are echoing with the name would need to include the following echo "<tr>"; echo "<a href='example.com/page.php?action=name&index=" . $row['name'] . "'><td>" . $row['name'] . "</td></a>"; etc etc echo "</tr>"; Then in your 'page.php' you would need if ( isset( $_GET['action'] ) && isset( $_GET['index'] ) ) { // This is the way to access the information being passed from the link with the supper global $_GET $action = $_GET['action']; $index = $_GET['index']; } switch $action { case 'name': getByName($index); break; default: getByName($index); } function getByName($index = null) { // This is where you would fetch and sort the information // Before you did anything else you MUST sanitize any data passed via the $_GET // as this is considered unsafe and to be from the user!!! } -------------------------------------------------- Now on to a little more important information! Your current script has the database access being performed in the front end view file, this is very risky and must never be done on any publicly accessible point. There is a nice set of tutorials on elated.com on the subject of php that I think you may find very useful. They are well written, easy to follow, and the projects are all good starting points to experiment with and expand with your own ideas too. This first one is 'Build a CMS in an afternoon' which is written by Matt Doyle, but it will probably take all day the first time to tackle it. Edited February 11, 201412 yr by Weedy101
February 12, 201412 yr Author Great thanks for this Weedy101 and I understand your security point. I will have a scoot at the info you passed on and let you know how I do. Much appreciated!
Create an account or sign in to comment