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
https://forums.phpfreaks.com/topic/118519-solved-displaying-rows/
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");
}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.