I'm creating a blog website linked to my Facebook account and I'm want to allow users to see older blogs. Therefore I'm creating a loop which outputs urls based the title, which then dynamically generates a new page based on the blog_id. However I have two problems.
- I only outputting one hyperlink and therefore doesn't loop through correctly
- Nothing is generating on the title.php page, and I get undefined index blog_id when submitting data through the url
==============================
$query="SELECT title FROM admin WHERE blog_id = $blog_id";
$result=mysqli_query($conn, $query) or die(mysqli_error());
$rstitle=mysqli_fetch_assoc($result);
mysqli_close($conn);
do { ?>
<a href="title.php?blog_id= <?php echo $rstitle['blog_id']; ?> ">
<ul>
<li id = "title"> <?php echo $rstitle['title']; ?> </li><br />
</ul>
</a>
<?php } while ($rstitle=mysqli_fetch_assoc($result)) ?>
Which links to the title.php page
<?php
$servername = "localhost";
$dbusername = "root";
$dbpassword = "";
$dbname = "blog";
// create connection
$conn = mysqli_connect($servername, $dbusername, $dbpassword, $dbname);
// check connection
if (!$conn)
{
die("Connection failed: " . mysqli_connect_error());
}
// we get here the connection to the database was successful
$query="SELECT blog FROM admin WHERE blog_id = $blog_id";
$result=mysqli_query($conn, $query)or die(mysql_error());
$rstitle=mysqli_fetch_assoc($result);
if (mysqli_num_rows($result) > 0)
{
echo "<table border='0' style='width:50%'>";
while($rstitle = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>" . $rstitle['blog'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
mysqli_close($conn);
?>