...

View Full Version : Getting one column from MySQL table



royal_lemon
08-20-2006, 01:41 PM
Index.php

<?php

include 'dbconnect.php';

$query="SELECT * FROM news";

$result=mysql_query($query);

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

echo "$title <br />";
echo "$day $month $year <br />";
echo "$entry <br />";
echo "Posted in: $category";
echo "<a href=\"post.php?id=$id\">Permalink</a>";

}
?>

post.php

<?php

$id = $_GET['id'];

include 'dbconnect.php';

$getsignle = mysql_query("SELECT column FROM table
WHERE id = $id");

$row = "mysql_fetch_array($getsingle)";

$title = '$row["title"]';
$entry = '$row["entry"]';
$year = '$row["year"]';
$month = '$row["month"]';
$day = '$row["day"]';
$category = '$row["category"]';

echo "$title <br />";
echo "$tentry <br />";
echo "$day ";
echo "$month ";
echo "$year <br />";
echo "$category";

?>

At index.php, I loop all the columns from the mysql table. I have a link that takes you to post.php?id=$id
At post.php, I want to only display the column where the field id = $id. But when I go to post.php?id=1
I only get this
$row["title"]

$row["day"] $row["month"] $row["year"]
$row["category"]

kaydara
08-20-2006, 02:44 PM
$row = "mysql_fetch_array($getsingle)";

try:

$row = mysql_fetch_array($getsingle);

royal_lemon
08-20-2006, 02:46 PM
I got when I tried that

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/thomas/public_html/news/post.php on line 10
$row["title"]

$row["day"] $row["month"] $row["year"]
$row["category"]

kaydara
08-20-2006, 04:07 PM
is the name of your column "column" ?

royal_lemon
08-20-2006, 04:25 PM
is the name of your column "column" ?

Hehe I just noticed:D

I got it working now, I just used the extract($row)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum