Ok, working on a blog engine. Small and somewhat unimpressive, basically following along with a tutorial. The tutorial basically has me write a little MySQL to query some test fields that we filled in manually. And here is what I get.

(see attachments)

The first one shows the read out from by web browser, and yes, I am positive Xampp is running. The second is what phpMyAdmin is telling me about fetching zero rows. Here is the code I have been using.

	$sql = "SELECT entries.*, catagories.cat FROM entries, catagories
			WHERE entries.cat_id = catagories.id
			ORDER BY dateposted DESC
			LIMIT 1;";
	$result = mysql_query($sql);
	$row = mysql_fetch_assoc($result);
	echo "<h2><a href='viewentry.php?id=" . $row['id'] . "'>" . $row['subject'] . "</a></h2><br />";
	echo "<em> In <a href='viewcat.php?id=" . $row['cat_id'] . "'>" . $row['cat'] . "</a> - Posted on " . date("D jS F Y g.iA", strtotime($row['dateposted'])) . "</em>";
	echo "<p>";
	echo nl2br($row['body']);
	echo "</p>";
	echo "<p>";
	$commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . "ORDER BY dateposted;";
	$commresult = mysql_query($commsql);
	$numrows_comm = mysql_num_rows($commresult);

The required heading is here:

	$db = mysql_connect($dbhost, $dbuser, $dbpassword);
	mysql_select_db($dbdatabase, $db);

<!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" xml:lang="en" lang="en">

<title><?php echo $config_blogname; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="styles/blog.css"/>


<div id="header">
	<h1><?php echo $config_blogname; ?></h1>
	[<a href="index.php">Home</a>]

<div id="main">

and the config file looks like this:

    $dbhost = "localhost";
	$dbuser = "root";
	$dbpassword = "";
	$dbdatabase = "dante2";
	$config_blogname = "Funny old world";
	$config_author = "Jono Bacon";
	$config_basedir = " Web Applications/blogtastic";

Thanks in advance for tip pointers and especial corrections. =D

Attachments Snap_2011.06_.10_18_.41_.33_001_.png 51.84 KB Snap_2011.06_.10_20_.16_.07_001_.png 48.18 KB
6 Years
Discussion Span
Last Post by Dante2

Two suggestions:

First, place a space between the closing quote and the word ORDER:

$commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . "ORDER BY dateposted;";

Also, if this does not fix the problem, then you might want to make sure that $commresult isn't an array[0] instead of a string...

$commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . "ORDER BY dateposted;";
	$commresult = mysql_query($commsql);
	$numrows_comm = mysql_num_rows($commresult);

Hope this helps.


Maybe, there is no post in the `comments` table. You can check manually in phpMyadmin.

SELECT name FROM comments WHERE blog_id = 'your_id' ORDER BY dateposted;

Just echo out your query

echo $commsql = "SELECT name FROM comments WHERE blog_id = " . $row['id'] . "ORDER BY dateposted;";

and put thr query in the SQL section of your phpmyadmin and see what is the error.


My apologies for being so long in getting beck. I was able to solve the problem with a friend, but thank you, everyone for all of your help. =)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.