It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Inserting data from MySQL in multiple parts of a page.

Moderator: Malcolm

Inserting data from MySQL in multiple parts of a page.

Postby rse on Tue Jun 07, 2005 9:49 am

Here is my current script:

Code: Select all
<!-- START index.php -->
<?php // Check for page_id from header info
$fetcher = $_REQUEST[page_id]
?>
<?php // If header is empty assume id = 1, otherwise header = header value
if ($fetcher == "") {
   $page="1";
} else {
   $page=$fetcher;
}
?>
<?php // Connect to the Database
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
exit('<p>Unable to connect to the ' .
     'database server at this time.</p>');
}

// Select the database
if (!@mysql_select_db('slbm_v1')) {
exit('<p>Unable to locate the ' .
     'database at this time.</p>');
}

?>
<?php // Select the table and perform the query

// Select all from table
$result = @mysql_query("SELECT * FROM Main_Articles WHERE Page_id = \"$page\"");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php // Output
while ($row = mysql_fetch_array($result)) {
echo $row['Article_title'] . '</br></br>' . $row['Article_data'];
} ?>

</body>
</html>


What i would like to be able to do is to insert $row[Image_url] for example (from the above query/table) and place it say at the bottom of the page. This is possible if i made the whole page PHP, but it would be much easier to do the bulk of it in HTML for the design side, then just put in PHP snippets where required. Does anyone know a way of doing this? I thought simply putting <?php echo $row[Image_url] ?> might work, but no joy.

Thanks as always for your help. You guys are the PHP dons! :)
Adam Williams
PHP Web Developer

Personal: http://30things.net
Blog: http://www.root-servers.co.uk
User avatar
rse
100+ Club
 
Posts: 141
Joined: Sun Oct 10, 2004 8:15 pm
Location: Leeds, UK

Postby rse on Tue Jun 07, 2005 10:16 am

I managed to solve this by changing the
Code: Select all
<?php // Output
while ($row = mysql_fetch_array($result)) {
echo $row['Article_title'] . '</br></br>' . $row['Article_data'];
}
to simply
Code: Select all
<?php // Output
$row = mysql_fetch_array($result); ?>
then just used <?php echo $row['Column_name'] ?> around my document.

I hope this will help any others who come across the same problem.

Cheers
Adam Williams
PHP Web Developer

Personal: http://30things.net
Blog: http://www.root-servers.co.uk
User avatar
rse
100+ Club
 
Posts: 141
Joined: Sun Oct 10, 2004 8:15 pm
Location: Leeds, UK

Postby webmaster on Tue Jun 07, 2005 12:06 pm

It's good with posters that can anser their own questions :D
Make sure to check out our TNX Review and Link Vault Review
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden


Who is online

Users browsing this forum: No registered users and 1 guest