I am currently re desigining a web site and would like to make things easyer by using php.

I have the basic design done in html tables and want to change the content of cells depending on what links are clicked on, or at least i think this is the right way to go about it.

can some one point me in the right direction please and if anyone has any examples of that would be great, I have used PHP breifly but really just want to learn what i need to know to get this done.

Thanks in advance,

Dave

Dani AI

Generated

As described, the objective is swapping table-cell content when different links are clicked. 's question about whether content lives in a database is important because it changes the workflow, and 's parameter-driven example is a common starter. The key additions are input validation, safe inclusion (no direct user-controlled file paths), and separating content from layout so future changes are easier.

A pragmatic file-based pattern keeps small HTML/PHP snippets under a content/ directory and maps safe slugs to filenames. This avoids directory traversal and accidental remote file inclusion. Example whitelist-based dispatcher:

<?php
$req = filter_input(INPUT_GET, 'page', FILTER_DEFAULT);
if (!$req || !preg_match('/^[a-z0-9_-]+$/i', $req)) { $req = 'home'; }

$map = [
  'home' => 'home.php',
  'about' => 'about.php',
  'products' => 'products.php'
];

$file = __DIR__ . '/content/' . ($map[$req] ?? 'home.php');
if (is_file($file)) {
  include $file;
} else {
  include __DIR__ . '/content/404.php';
}
?>

For database-driven sites, store a pages table with a unique slug and a body column, then fetch by slug with PDO and prepared statements (trusted HTML only, or store Markdown/plain text and render safely). Example PDO pattern:

<?php
$pdo = new PDO('mysql:host=localhost;dbname=site;charset=utf8mb4','user','pass',[
  PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$stmt = $pdo->prepare('SELECT title, body FROM pages WHERE slug = :slug LIMIT 1');
$stmt->execute([':slug' => $req]);
$page = $stmt->fetch(PDO::FETCH_ASSOC);
echo $page ? $page['body'] : 'Not found';
?>

Troubleshooting and cautions: enable errors during development (ini_set('display_errors',1); error_reporting(E_ALL);), confirm files are parsed as PHP, and never construct include paths directly from raw input — use a whitelist or DB lookup. For input functions see filter_input() and for safe DB access see PDO. For maintainability, consider replacing table-based layout with CSS and keep header/footer templates separate from content snippets.

Recommended Answers

All 2 Replies

Are you stroring content in the Database then?

or doing some sort of calculion in the "cells"?

Senexom asks a good question--what do you REALLY want to do? You could have code such as this:

<table>
  <tr>
	<td>

<?php

$page_action = $_GET['a'];
switch($page_action) {
case "action1":
  echo "You chose action 1.";
  break;
case "action2":
  echo "You chose action 2.";
  break;
default:
  echo "Welcome to my page.";
}

?>

	</td>
  </tr>
</table>

<a href="mypage.php?a=action1">Action 1</a>
<a href="mypage.php?a=action2">Action 2</a>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.