Jump to content

PLEASE PLEASE HELP - template / variable in query


Recommended Posts

hi there

 

I am quite new with php, my goal is to have a template styled page which displays all my database rows separately, for example for the 5th row, the relevant record would be displayed on www.example.com/index.php?id=5 I have done the below code, this parses only the first record and does not do any more or change by changing ?id=5 / ?id=4 etc, PLEASE PLEASE PLEASE help me do this as I have made a massive database and it is currently pointless as I cant display any of it.

 

 

I don't really know what I am doing and havn't seen a tutorial which shows what I am trying to achieve, I have been looking around the internet for hours.

 

 

<?php

// Connects to your Database

mysql_connect("localhost", "login", "password") or die(mysql_error());

mysql_select_db("news") or die(mysql_error());

// Query

$id = $_GET['id'];

$data = mysql_query("SELECT * FROM `news` WHERE `id`='.$id.'") or die(mysql_error());

 

 

// Results

while($info = mysql_fetch_array( $data ))

{

Print "<center><b>".$info['title'] . " </b> - Flash Games<br>";

Print "<center><b>".$info['id'] . " </b>";

}

Print "</table>";

?>

 

Hi,

 

It's getting pretty late and my eyes aren't as sharp as they are at other times of the day, but it looks like you have some unnecessary dots in your sql query. Try:

 

$data = mysql_query("SELECT * FROM `news` WHERE `id`='$id'") or die(mysql_error());

 

Let me know what that does for you.

 

Cheers,

Darren.

The "dots" are what is known as the concatenation operator (http://www.php.net/manual/en/language.operators.string.php), which is perfectly fine. However, he isn't using it right. This should work (as well as should recklessgeneral's) :

$data = mysql_query("SELECT * FROM `news` WHERE `id`='" . $id . "'") or die(mysql_error());

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.