Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Create hyperlink from display

Featured Replies

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 :-)

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 by Weedy101

  • 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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.