bfsog
03-20-2005, 01:47 AM
I am trying to implement a system, which outputs a list of links onto a page, an example link being
<a href='index.php?var=" . $row['id'] . "'>" . $row['title'] . "</a>
[/code]
When that is clicked on, I want articles.php to only show that record.
The code I have does not do anything, other than change the address bar to the links href.
[code]
<?php
session_start();
header("Cache-control: private");
include("connect.php");
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
else if(isset($_POST['id'])) {
$id = $_POST['id'];
}
else {$id=1;}
if ((isset($_POST['id'])) || (isset($_GET['id']))) {
$sql = "SELECT id,title,username,comment FROM content where id='$id' LIMIT 1";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
$query = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo'<p class="post">';
echo '<span style="font-size: 16px;">'.$row[title].'</span> posted by '.$row[username].' on '.$row[date].'<br /><br />';
$thebrdata = $row[comment];
echo nl2br($thebrdata);
echo '</p>';
echo '<br />';
$numrows++;
}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head><title>blogit</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div id="leftcontent">
<!-- Define PHP Show Posts code //-->
<?php
include ("connect.php");
$query = "SELECT * FROM content ORDER by id DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows == "0") {
echo "Be the first to add a comment!<br><br>";}
else {
while($row = mysql_fetch_array($result))
{
echo'<p class="post">';
echo '<span style="font-size: 16px;">'.$row[title].'</span> posted by '.$row[username].' on '.$row[date].'<br /><br />';
$thebrdata = $row[comment];
echo nl2br($thebrdata);
echo '</p>';
echo '<br />';
$numrows++;
}}
?>
</div>
<div id="rightcontent">
<p><!-- Define PHP for the latest posts //-->
<?php
include ("connect.php");
$query = "SELECT id, title, date FROM content ORDER by id DESC LIMIT 5";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
echo " <span style='padding-right: 10px;'><a href='index.php?var=" . $row['id'] . "'>" . $row['title'] . "</a></span> - " .$row['date'] . "";
echo "<br />";
$numrows++;
}
?>
Thanks in advance
<a href='index.php?var=" . $row['id'] . "'>" . $row['title'] . "</a>
[/code]
When that is clicked on, I want articles.php to only show that record.
The code I have does not do anything, other than change the address bar to the links href.
[code]
<?php
session_start();
header("Cache-control: private");
include("connect.php");
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
else if(isset($_POST['id'])) {
$id = $_POST['id'];
}
else {$id=1;}
if ((isset($_POST['id'])) || (isset($_GET['id']))) {
$sql = "SELECT id,title,username,comment FROM content where id='$id' LIMIT 1";
$result = mysql_query($sql);
$numrows = mysql_num_rows($result);
$query = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo'<p class="post">';
echo '<span style="font-size: 16px;">'.$row[title].'</span> posted by '.$row[username].' on '.$row[date].'<br /><br />';
$thebrdata = $row[comment];
echo nl2br($thebrdata);
echo '</p>';
echo '<br />';
$numrows++;
}}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head><title>blogit</title>
<link rel="stylesheet" href="main.css" type="text/css">
</head>
<body>
<div id="leftcontent">
<!-- Define PHP Show Posts code //-->
<?php
include ("connect.php");
$query = "SELECT * FROM content ORDER by id DESC";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
if ($numrows == "0") {
echo "Be the first to add a comment!<br><br>";}
else {
while($row = mysql_fetch_array($result))
{
echo'<p class="post">';
echo '<span style="font-size: 16px;">'.$row[title].'</span> posted by '.$row[username].' on '.$row[date].'<br /><br />';
$thebrdata = $row[comment];
echo nl2br($thebrdata);
echo '</p>';
echo '<br />';
$numrows++;
}}
?>
</div>
<div id="rightcontent">
<p><!-- Define PHP for the latest posts //-->
<?php
include ("connect.php");
$query = "SELECT id, title, date FROM content ORDER by id DESC LIMIT 5";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
echo " <span style='padding-right: 10px;'><a href='index.php?var=" . $row['id'] . "'>" . $row['title'] . "</a></span> - " .$row['date'] . "";
echo "<br />";
$numrows++;
}
?>
Thanks in advance