I posted this a day or so ago but I still can't get it to work...
I'm doing a very simple blog script.
The main blog content is held in one DB and the info for each of the comments in another, with a field for the blog's ID in that DB so I can link the two.
What i'm trying to do is have a main page that comes up showing all the blog posts, along with the number of comments each one has (so I need to query two DBs on the same page).
I'm using the following code, and I (ah poor newbie) can't figure out why it won't work...
<?php
#get info from db
$sql = "select * from blogpost order by time desc";
$rs = @mysql_query($sql);
#loop through records and generate table
while ($row = mysql_fetch_array($rs))
{
?>
<table cellpadding="3" cellspacing="0" width="100%">
<tr>
<td width="100%"><b><? echo $row["title"]; ?></b><br>
<?php
#get the date/time info
$datetime = $row["time"];
$year = substr($datetime,0,4);
$mon = substr($datetime,4,2);
$day = substr($datetime,6,2);
$hour = substr($datetime,8,2);
$min = substr($datetime,10,2);
$sec = substr($datetime,12,2);
$orgdate = date("d.m.y @ g:i a",
mktime($hour,$min,$sec,$mon,$day,$year));
?>
It was: <? echo $orgdate; ?><br>
Music: <? echo $row["musicartist"]; ?> - <? echo $row["musictitle"]; ?><br>
Mood: <? echo $row["mood"]; ?><br><br>
<? echo $row["content"]; ?><br><br>
<? $sql2 = "select count(*) from blogcomments where id = $row["id"]";
$rs2 = mysql_query($sql2) or die (mysql_error());?>
<a href="comments.php?ID=<? echo $row["id"]; ?>">
<? echo $rs2 ?> comments</a> |
<? #get info from db
$sql3 = "select * from blogpost order by time desc";
$rs3 = @mysql_query($sql3); ?>
<a href="commentsadd.php?ID=<? echo $row["id"]; ?>">Add Comment</a><br>
</td>
</tr>
</table>
<br><br>
<? } ?>
(Essential code only)
Now, when I switch
<? $sql2 = "select count(*) from blogcomments where id = $row["id"]";
to
<? $sql2 = "select count(*) from blogcomments where id = 1";
it kind of works but shows up on the main page like:
Resource id #5 comments | Add Comment
When I try to run the existing code I get the error:
Parse error: parse error, unexpected '"', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Apache\Apache2\htdocs\testing\v1.0\index2.php on line 98
How can I fix it? 🙁