Recordset within a recordset? PHP/MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidlee
Forum Newbie
Posts: 2
Joined: Tue Feb 08, 2005 4:33 pm

Recordset within a recordset? PHP/MySQL

Post 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:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

should probably have markers in the table row that tell you what to do with the data stored in the body..
davidlee
Forum Newbie
Posts: 2
Joined: Tue Feb 08, 2005 4:33 pm

Post by davidlee »

Ahhh... markers? Sorry, but could you elaborate a little or point me to similar example. Thanks for yout time.

David
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

markers... like identifiers.. coded fields that hold meaning..
Post Reply