Jump to content

help with hyperlink triggering an sql query


melting_dog

Recommended Posts

HI all,

 

Sorry this question might sound very 'newbie'.

 

I have an HTML hyperlink and when clicked i want to run a query that will display the results on the page the hyperlink links to.

 

Can anyone give me the basic structure of how this might be done?

 

Cheers

This is a php question rather than that of mysql, but anyway....

 

Given...

<a href="foo.php?id=12">click</a>

 

foo.php might look like....

<?php
if (isset($_GET['id'])) {
  $id = mysql_real_escape_string($_GET['id']);
  $sql = "SELECT a,b FROM tbl WHERE id = $id LIMIT 1";
  if ($result = mysql_query($sql)) {
    if (mysql_num_rows($result)) {
      $row = mysql_fetch_assoc($result);
      echo $row['a'] . " " . $row['b'];
    }
  }
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.