Forum Moderators: coopster

Message Too Old, No Replies

Help a total Newbie?

Trying to display info from a database

         

wilsoncj

10:49 am on Aug 3, 2006 (gmt 0)

10+ Year Member



I'm totally new to php (started yesterday), so this might be all wrong, but I wonder if you guys could have a look and push me in the right direction?

I'm trying to display info from a database. It has 2 text columns, "Head" and "Story".

Here's the code (without the real password obv:):

<html>
<head></head>
<body>

<?php
$host = "localhost";
$user = "outpost_admin";
$pass = "pass";
$dbname = "test1";

$dbh=mysql_connect ("$host", "$user", "$pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("$dbname");

$sql = 'SELECT `news` . `Head` , `news` . `Story` '
. ' FROM news '
. ' ORDER BY `news` . `Head` ASC , `news` . `Story` ASC LIMIT 0, 30 ';

$query = mysql_query($sql);

while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['Head'],": ",$row['Story'];
}

?>

</body>

When I load the page, all I see it this and nothing else:

",$row['Head'],": ",$row['Story']; }?>

omoutop

11:22 am on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



the error is in your echo statement:
change it to this echo "<p>".$row['Head'].": ".$row['Story']."</p>"; and it should work (not tested)

henry0

11:54 am on Aug 3, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Wilsoncj, Welcome on WebmasterWord!

Have a look HERE [webmasterworld.com]

Then go back to the top of the forum page and search our library; lots of goodies in there :)