plastik77 Posted July 3, 2007 Share Posted July 3, 2007 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 https://forums.phpfreaks.com/topic/58218-solved-hyperlinking-table-cells-to-a-php-script/ Share on other sites More sharing options...
corillo181 Posted July 3, 2007 Share Posted July 3, 2007 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 https://forums.phpfreaks.com/topic/58218-solved-hyperlinking-table-cells-to-a-php-script/#findComment-288675 Share on other sites More sharing options...
HuggieBear Posted July 3, 2007 Share Posted July 3, 2007 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 https://forums.phpfreaks.com/topic/58218-solved-hyperlinking-table-cells-to-a-php-script/#findComment-288678 Share on other sites More sharing options...
plastik77 Posted July 3, 2007 Author Share Posted July 3, 2007 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 https://forums.phpfreaks.com/topic/58218-solved-hyperlinking-table-cells-to-a-php-script/#findComment-288687 Share on other sites More sharing options...
HuggieBear Posted July 3, 2007 Share Posted July 3, 2007 That's right, then it's as easy as using $_GET['test_id'] in the page being called. Don't forget to use the solved button to mark this topic as solved. Regards Huggie Link to comment https://forums.phpfreaks.com/topic/58218-solved-hyperlinking-table-cells-to-a-php-script/#findComment-288690 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.