Jump to content

[SOLVED] Hyperlinking table cells to a PHP script


plastik77

Recommended Posts

Hi - apologies if this is a embarrassingly simple query (pretty new to PHP and a newbie to the forums), but if anyone could help that would be appreciated. Basically, I'm creating some test creator software for lecturers at my Uni. I have a Test History page where lecturers can view previous tests they have created (displayed in table format). This is straightforward php/mysql so far, however, I want to be able to hyperlink each test created so that the lecturer can drill into the details of a test if he wants. On clicking a hyperlinked test, a php script will be called which will take the specific test clicked as a GET parameter and will insert it into an SQL query which will return the details of that test on another page. However, I'm not quite sure how to implement this - I realise that I need to use a form in order to pass the parameter to a PHP script, but I don't know to get the hyperlink click to act as a form submission. If anyone can offer any advice that would be great - I've searched numerous forums and haven't found anything on this specific problem.

Cheers

 

p.s here is the code as it stands

 

$username = $_SESSION['user'];

$query = mysql_query("select * from Test where createdBy = '".$username."'");

$numrows = mysql_num_rows($query);

 

if ($numrows != 0)  // If matching lecturer

{

echo "      <table border='1'>

<tr>

<th>Test Name</th>

<th>Date Created</th>

</tr>";

for ($i=0;$i<$numrows;$i++)

{

$row = mysql_fetch_array($query);

$name = $row['name'];

$date = $row['dateCreated'];

$year = substr($date, 0, 4);

$month = substr($date, 5, 2);

$day = substr($date, 8, 2);

echo "<tr>";

echo "<td>".$name."</td>";

echo "<td>".$day."/".$month."/".$year."</td>";

echo "</tr>";

}

echo "</table>";

Link to comment
Share on other sites

how about adding a extra row which says

 

more info about this topic

 

with the topic id attach to it..

 

so it would be <a hef="whatever.com?$topic_id=123">

 

and on the next page just search for it.

 

select from table where topic_id=$_GET['topic_id'].

Link to comment
Share on other sites

If your table named Test has a unique id as a primary key then this shouldn't be too difficult.  Just include the id as a GET parameter in the URL.  Where you have:

 

echo "<td>".$name."</td>";

 

Change to this:

 

echo "<td><a href='test_detail.php?test_id=" . $id . "'>" . $name . "</a></td>";

 

Where I have test_detail.php, change this to the name of your detail page, and where I have $id, change this to the name of the id column in your database.

 

Regards

Huggie

Link to comment
Share on other sites

thanks for both replies - that makes perfect sense and each test has a unique id so that part is straightforward

 

the main thing i had trouble understanding was how to actually submit the form to call the script without using a submit button - but by adding the item id into the url, that allows me to GET the test ID from the url

 

cheers for your time!

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.