Index.php needs to show a record from database


Hopefully this is the simpliest question ever. I have just produced my first php content managed site.
Basically the index.php needs to show the record from the data base with the ID of 1. Obviously when the browser loads the site it only looks for index.php and would not include the record id on the end of it. Hence it would only load the empty default page I’ve created to disploay records in.
Is there a way round this? There must be, surely!

Any help would be fantastic.

Priming a Variable.

$id = (isset($_GET['id'])) ? $db->real_escape_string($_GET['id']) : 1;

Explanation: The line reads: “If $_GET[‘id’] is set (exists on the end of your URL), use the database object to escape the string (if you’re using procedural, this will change into mysql(i)_real_escape_string() and set $id to that. If it isnt, set $id to 1.”

Ternary Operator

// change POST to GET if you are using that method ie index.php?id=1
if( ! isset($_POST['id']) ){
$_POST['id'] = 1;

// carry on with script

First of all many thanks for your very speedy replies.

I have this on the in the <head> of the file, is it the right bit?

$colname_pages = “-1”;
if (isset($_GET[‘cms_id’])) {
$colname_pages = $_GET[‘cms_id’];

and are you suggesting I change it to:

$colname_pages = “-1”;
if (isset($_POST[‘cms_id’])) {
$colname_pages = $_POST[‘cms_id’]=1;

The method i’m useing is index.php?cms_id=3

Thanks again

Missed out an explanation mark

$colname_pages = “-1”;
if ( ! isset($_POST[‘cms_id’])) {
$colname_pages = $_POST[‘cms_id’]=1;

This works great, thank you again very much.

Hi Again,

Sorry, my index.php now displays the right record when it opens, but unless I put the whole url in, the browser doesn’t access index.php, maybe because it is looking for an index.html.

For example - doesn’t load anything but - does work.

How do I get the browser to acknowledge the index.php?

Have a good weekend.

That looks like an apache setting, you want the default to be index.php rather than index.html.

They might both be set, if index.html contains nothing just delete it and try again.

That is more to do with your server setup - Apache needs to be set up to look for index.php. Maybe there is an index.html or something that is being loaded in preference?