Hi all, I have written some php code to display my pages + can add parent id numbers to the row in the database - but what I can’t do is create some code to show the sub-pages directly under the parent page in a menu.
Here is the sql code:
CREATE TABLE IF NOT EXISTS `pages` (
`id` int(20) NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL,
`intro` varchar(255) NOT NULL,
`entry` longtext NOT NULL,
`creation_date` datetime NOT NULL,
`parent_id` int(11) NOT NULL,
PRIMARY KEY (`id`)
and here is the php code to display the pages:
[php]
// Make the query:
$q = “SELECT id, title, intro, DATE_FORMAT(creation_date, ‘%M %d, %Y’) FROM pages ORDER BY creation_date ASC LIMIT $start, $display”;
$r = mysqli_query ($dbc, $q); // Run the query.
// Table header.
echo ’
Title |
Intro |
Edit |
Delete |
';
// Fetch and print all the records:
$bg =’#eeeeee’; // Set the initial background colour.
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$bg = ($bg==’#eeeeee’ ? ‘#ffffff’ : ‘#eeeeee’); // Swich the bacground color.
echo '<tr bgcolor="' . $bg . '">
<tr>
<td align="left"><a href="preview_page.php?id=' . $row['id'] . '">' . stripslashes($row['title']) . '</a></td>
<td align="left">' . stripslashes($row['intro']) . '</td>
<td align="left"><a href="edit_page.php?id=' . $row['id'] . '">Edit</a></td>
<td align="left"><a href="delete_page.php?id=' . $row['id'] . '">Delete</a></td>
</tr>
';[/php]
I suppose I need a second query and while loop. But I am not sure what to put and how to make a search of sub-pages to the page that has been displayed.
Also I have tried searching via Google etc but can’t find a clear answer - or not one that I recognise as such.
Any advice or direction would be appreciated.
Cheers,
Colin