Stoosh Posted March 19, 2009 Share Posted March 19, 2009 Hello, I've started teaching myself PHP heavily after a big learning curve with design, html & css. If you have a look at http://www.aftersunset.com.au/enquiry/test.php, its just a basic query from a database, what I'm looking to do is add an extra table column with a link such as http://www.aftersunset.com.au/enquiry/test.php?id=1 which opens to a page which displays the comments or info that the user submitted which is also stored in the database (row is "comments") <?php require_once('dbconnect.php');?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <head> </head> <body> <?php // query $query = "SELECT * FROM enquiry"; // execute $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // check for rows if (mysql_num_rows($result) > 0) { // yes // print, repeat echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['company']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['phone']."</td>"; echo "</tr>"; } echo "</table>"; } else { // no // error page echo "No rows found!"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connect); ?> </body> </html> This is my first PHP script handwritten so it may be a little sloppy Quote Link to comment https://forums.phpfreaks.com/topic/150236-solved-dynamic-link-to-open-mysql-query-in-a-new-page/ Share on other sites More sharing options...
dropfaith Posted March 20, 2009 Share Posted March 20, 2009 add this line where you want it to display in your table echo '<td><a href=" http://www.aftersunset.com.au/enquiry/test.php?id=' . $id . '">' . $id . '</a></td>'; will create the links then look up the php command $GET to understand how to retrive the data heres a quick example $Name = mysql_escape_string(trim(htmlentities($_GET['Name']))); $query = "SELECT * FROM business WHERE Name = '$Name'"; of the get method to run a query Quote Link to comment https://forums.phpfreaks.com/topic/150236-solved-dynamic-link-to-open-mysql-query-in-a-new-page/#findComment-789086 Share on other sites More sharing options...
Stoosh Posted March 21, 2009 Author Share Posted March 21, 2009 Thanks very much!! It's calling the data but the table is still shown, how do I remove the table when the ID link is clicked? <?php // create query $query = "SELECT * FROM enquiry"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['id']."</td>"; echo "<td>".$row['name']."</td>"; echo "<td>".$row['company']."</td>"; echo "<td>".$row['email']."</td>"; echo "<td>".$row['phone']."</td>"; echo '<td><a href="http://www.aftersunset.com.au/enquiry/test.php?id=' . $row['id'] . '">View Comments</a></td>'; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "No rows found!"; } $sql = "SELECT * FROM `enquiry` WHERE `id` = " . mysql_real_escape_string ( $_GET['id'] ); if ( mysql_query ( $sql ) ) { $query = mysql_query ( $sql ); $row = mysql_fetch_assoc ( $query ); echo $row['comments']; } else { die ( mysql_error () ); } // free result set memory mysql_free_result($result); // close connection mysql_close($connect); ?> Quote Link to comment https://forums.phpfreaks.com/topic/150236-solved-dynamic-link-to-open-mysql-query-in-a-new-page/#findComment-790116 Share on other sites More sharing options...
BigTime Posted March 21, 2009 Share Posted March 21, 2009 the table is still shown because you are calling to the same page try linking to from test.php to test2.php?id='$id' then on test2.php you can re-query data WHERE id='$id'; (because you just passed that value in your URL) and format how you like. OR you could maybe add a clause if (isset($id)){ and do your formatting there.... Quote Link to comment https://forums.phpfreaks.com/topic/150236-solved-dynamic-link-to-open-mysql-query-in-a-new-page/#findComment-790126 Share on other sites More sharing options...
Stoosh Posted March 21, 2009 Author Share Posted March 21, 2009 I knew that was the reason, I just didnt know how the right code to fix Thanks Quote Link to comment https://forums.phpfreaks.com/topic/150236-solved-dynamic-link-to-open-mysql-query-in-a-new-page/#findComment-790134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.