The way my files are set up, I have a class that I've made called "page.php" and it's the layout of the page with navigation and html tables and all that. Then I have an include called db.php and it has the call to the database. Finally, I have the actual page (ex. "home.php" "about_us.php" etc.) Those pages grab the page.php, and the db.php - making a call to the db, and getting the relevant information to that page ($pageid). The home.php page has a $pageid of 1, and grabs all the rows of the table w/ pageid=1.
Right now I'm only getting one row of the table, and not the subsequent rows (and yes, right now in the db there are several rows with pageid=1).
I know my problem is that I need a conditional loop that will run and check how many rows have been returned, and then another loop that will increment through the returned rows. I don't know how or where to put this loop.
Here's my code:
page.php (this is the page class, and this is only the part of the code i thought was applicable)
Code: Select all
<?
function SetContent($newcontent)
{
$this->content = $newcontent;
}
function Display()
{
echo "<html>\n<head>\n";
echo $this->content;
echo "</body>\n</html>\n";
}
?>It calls to the database, and returns the information from the table:
Code: Select all
<?
$db = mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db('localhost') or die(mysql_error());
$sql = "select * from content
where pageid = '$pageid'
order by contentid desc
";
$sqlresult = mysql_query ($sql, $db);
$row = mysql_fetch_array ($sqlresult);
// Close the connection
mysql_close($db);
?>Code: Select all
<?
$pageid = 1;
require ("../inc/page.php");
include ("../inc/db.php");
$homepage = new Page();
$homepage -> SetContent("<h1>".$rowї3]."</h1><p>".$rowї4]."</p>"
);
$homepage -> Display();
?>I don't know if I'm explaining this clearly. So any questions, comments, or anything would be much appreciated. I've been trying to figure this out for a while now, and I keep running up against a wall. I understand it's basically just getting several rows of info out of an array, but I haven't been able to make it happen.
Thanks for any help.