简体   繁体   中英

Create hyperlink in table using php with sql

I'm sorry if this is unclear or difficult to understand, but explaining what I am attempting to do isn't that easy over text. I am trying to create a table of data for a book review site, however I want the title of the post to be a hyperlink to a section for comments for just that post (ID specific), while still having the name of the hyperlink be the variable of the post title (multiple titles are going to be present). The current problem I am having is that I cannot create this hyperlink (when I try to use it currently I just get a blank page with my header) and I do not know how to link that specific hyperlink to the ID specific post (I'm aware my bookcomments.php?id=id is most likely the issue here, not sure how to fix that) Here is my code currently (un-working).

if(isset($_GET['id']))
{

$sSql = "SELECT * FROM timestamp WHERE post_id='".$_GET['id']."'";

$oResult = mysql_query($sSql);

$aRow = mysql_fetch_assoc($oResult);
}

function displayRowEdit($fpostid, $lauthor, $posttitle, $booktitle, $post, $datepublished)
{
echo "<tr>";
echo "<td> $fpostid </td>";
echo "<td> $lauthor </td>";
echo "<td> <a href="sod73.asu.edu/~pspiotto/BlogTest/bookcomments.php?id=id"> $posttitle</a></td>";
echo "<td> $booktitle </td>";
echo "<td> $post </td>";
echo "<td> $datepublished </td>";
echo "<td> <form action=\"delete.php?id=$fpostid\" method=\"post\">";
echo "<input type=\"hidden\" name=\"id\" value=$fpostid />";
echo "<input type=\"submit\" value=\"DELETE\" > </form></th>";

echo "<td> <form action=\"update.php?id=$fpostid\" method=\"post\">";
echo "<input type=\"submit\" value=\"UPDATE\" > </form></th>";
echo "</tr>";

}

change this :

echo "<td> <a href="sod73.asu.edu/~pspiotto/BlogTest/bookcomments.php?id=id"> $posttitle</a></td>";

to this:

 echo "<td> <a href='//sod73.asu.edu/~pspiotto/BlogTest/bookcomments.php?id=$fpostid'> $posttitle</a></td>";

You need to insert the post ID into the URL:

echo "<td> <a href='bookcomments.php?id=$fpostid'> $posttitle</a></td>";

Also, you have to be careful about the types of quotes you use. Since you're using double quotes for the echo argument, you should use single quotes for the HTML attribute parameters (or you need to escape embedded double quotes).

If the bookcomments.php script isn't on the same server as the script with the link, you need to use the full URL, like in your version. But when you include a hostname in the URL, you have to put // before it, otherwise it's treated as a folder name on the current server.

echo "<td> <a href='//sod73.asu.edu/~pspiotto/BlogTest/bookcomments.php?id=$fpostid'> $posttitle</a></td>";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM