Page 1 of 1

Recordset within a recordset? PHP/MySQL

Posted: Tue Feb 08, 2005 4:48 pm
by davidlee
Hi all, I started building a content management app for a new site and I stumbled into a problem. I'm calling each page from a database (see code below). But, one of the pages I want to call I want to have return a list of news items that the user could click to bring up the detail. I can get this to work if this list page is by itself, but I get errors when attempting to copy the code into the body field of the table. I'm guessing it's freakin' out because I'm attempting to call a recordset (news list) within a recordset (the page itself). For example, using the code below, if I use id 123, it would bring back a single recordset and display it contents -- usually just text. But, id 456 might contain code (in the body field) to generate another recordset to display code. Make sense? How do I do this? Can I do this? Thanks!

Code: Select all

<body>
<div id="wrapper">
<? 
require("inc/siteheader.inc");
require("inc/leftnav.inc");
require("inc/conn.inc"); 

$id=$_GET&#1111;'id'];

$query=" SELECT * FROM content WHERE id='$id'";
$result=mysql_query($query);
$num=mysql_numrows($result);

$i=0;
while ($i < $num) &#123;
$id=mysql_result($result,$i,"id");
$date=mysql_result($result,$i,"date");
$title=mysql_result($result,$i,"title");
$body=mysql_result($result,$i,"body");

$title = stripslashes($title);
$body = stripslashes($body);
?>

<div id="content">

	<h3><? echo $title; ?></h3>
	<p><? echo $date; ?></p>
	<p><? echo $body; ?></p>
	
</div>

<?
++$i;
&#125;
mysql_close();
?>

<? 
require("inc/sitefooter.inc");
?>
</div>
</body>
David


feyd | :roll:

Posted: Tue Feb 08, 2005 4:54 pm
by feyd
should probably have markers in the table row that tell you what to do with the data stored in the body..

Posted: Wed Feb 09, 2005 7:53 am
by davidlee
Ahhh... markers? Sorry, but could you elaborate a little or point me to similar example. Thanks for yout time.

David

Posted: Wed Feb 09, 2005 8:41 am
by feyd
markers... like identifiers.. coded fields that hold meaning..