Hi all,
I would like to keep one variable in memory for
my next sql query.
mysql_connect('localhost', 'root', '')
or die("Mysql connection failed");
mysql_select_db("blog")
or die("Can't find database 'blog'");
$sql = "select * from user,article where article.userID=user.ID order by article.ID desc limit 5";
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
printf("<hr><h3><a href=\"article.php?id=%d\">%s</a></h3><b>author %s, date %s</b><p>%s</p>",$row['ID'],
$row['title'], $row['username'],$row['timestamp'], $row['content']);
}
my next query to get id number id=%d , how to have it ?
$sql = "select a.ID,c.content from article as a inner join comment as c on a.ID = c.articleID
group by a.ID,c.content order by a.ID desc limit 5 where a.ID = ???? ";
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
//printf($row['ID'],$row['content']);
printf("<hr>%s<p>%s</p>",$row['ID'], $row['content']);
}
please help me, I really appreciated.
Thank you,
I would like to keep one variable in memory for
my next sql query.
mysql_connect('localhost', 'root', '')
or die("Mysql connection failed");
mysql_select_db("blog")
or die("Can't find database 'blog'");
$sql = "select * from user,article where article.userID=user.ID order by article.ID desc limit 5";
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
printf("<hr><h3><a href=\"article.php?id=%d\">%s</a></h3><b>author %s, date %s</b><p>%s</p>",$row['ID'],
$row['title'], $row['username'],$row['timestamp'], $row['content']);
}
my next query to get id number id=%d , how to have it ?
$sql = "select a.ID,c.content from article as a inner join comment as c on a.ID = c.articleID
group by a.ID,c.content order by a.ID desc limit 5 where a.ID = ???? ";
$result = mysql_query($sql);
if (!$result)
die("SQL error: ".$sql." ERROR: ".mysql_error());
while ($row = mysql_fetch_assoc($result)) {
//printf($row['ID'],$row['content']);
printf("<hr>%s<p>%s</p>",$row['ID'], $row['content']);
}
please help me, I really appreciated.
Thank you,