Jump to content

[SOLVED] Displaying rows...


geudrik

Recommended Posts

I feel a bit nubish asking this question, but it's been so long since I've coded PHP that I can't seem to remember anything.

 

What I want to do is very basic.  Connect to db, select rows, display them in a dynamic table that expands as needed based on number of rows in db. 

 

Below is my code.  What piece am I missing to make the table work?

 

<?php

include_once('includes/db.php');

dbconnect();


$sql = "SELECT * FROM pages WHERE archived = '0'";
$reqult = mysql_query($sql) or die(mysql_error());

while( $row = mysql_fetch_array($result) ) {

$id        = $row['id'];
$urltitle  = $row['pagetitle'];
$pagetitle = $row['contenttitle'];
$body      = $row['content'];

echo('<table width="100%" border="1" cellspacing="0" cellpadding="0">');

foreach($row as ...) #is foreach what i'm looking to use?
{

	echo('  <tr>
				<td>$id</td>
				<td>$urltitle</td>
				<td>$pagetitle</td>
				<td>$body</td>
			</tr>
		');

}

echo('</table>');

mysql_close();

?>

Link to comment
Share on other sites

<?php 
session_start();

if ($_SESSION['loggedin'] != true) { header("Location: ../index.php"); }
if (!isset($_POST)) { header("Location: index.php"); }

if (isset($_POST['newpage'])) {

include_once('../includes/db.php');

dbconnect();

$url_title    = $_POST['urltitle'];
$public_title = $_POST['publictitle'];
$body         = $_POST['pagebody'];

$sql          = "INSERT INTO pages (pagetitle, contenttitle, content) VALUES ($url_title, $public_title, $body)";
mysql_query($sql) or die(''.mysql_error().'<br />The query that was executed was: <br /> $sql');
mysql_close();
$_SESSION['message'] = 'New page added successfully';
echo('Click Here to go back to the Admin Page - Use FireFox and you won\'t see these messages...');
header("Location: index.php");
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.