I need help with retrieving the data. This is mainly copynpaste code, but it's a start. I get an unknown category error. The table has two columns, the int key and a text field.
<?php
$username = "root";
$password = "-------";
$database = "grav";
$host = "localhost";
# connect to database
$cid = mysql_connect($host,$username,$password);
if (!$cid) { echo("ERROR: " . mysql_error() . "\n"); }
?>
<html>
<head>
<title>Display Posts</title>
</head>
<body>
<?php
$category = "Posts";
# setup SQL statement
$SQL = " SELECT * FROM posts WHERE category = '$category' ";
# execute SQL statement
$retid = mysql_db_query($database, $SQL, $cid);
# check for errors
if (!$retid) { echo( mysql_error()); }
else {
# display results
echo ("<h3><b>$category</b></h3>\n");
while ($row = mysql_fetch_array($retid)) {
$post = $row["post"];
echo ($post."<br/>\n");
}
}
?>
</body>
</html>
please replace this part of your code:
<?php
$category = "Posts";
# setup SQL statement
$SQL = " SELECT * FROM posts WHERE category = '$category' ";
# execute SQL statement
$retid = mysql_db_query($database, $SQL, $cid);
# check for errors
if (!$retid) { echo( mysql_error()); }
else {
# display results
echo ("<h3><b>$category</b></h3>\n");
while ($row = mysql_fetch_array($retid)) {
$post = $row["post"];
echo ($post."<br/>\n");
}
}
?>
with this one:
$category = "Posts";
# setup SQL statement
$SQL = " SELECT * FROM posts WHERE category = '$category' ";
# execute SQL statement
$retid = mysql_query($query);
$result=mysql_query($retid) or die (mysql_error());
$num=mysql_num_rows($result);
# display results
while ($i<$num)
{
$post=mysql_result($result,$i,"post");
echo "<h3><b>'.$category.'</b></h3>\n";
echo $post;
$i++;
}
I think that you are getting an unknown column because the field "post" is not the column name of what you are trying to display.
Look at your database, look what field do you want to display and replace "post" in
$post=mysql_result($result,$i,"post");
with that field.
Or better yet please display here all your table fields so I can guide you.