writing mysql data to multiple files on a web site with php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
obcbeatle
Forum Newbie
Posts: 5
Joined: Fri Mar 07, 2008 9:21 am

writing mysql data to multiple files on a web site with php

Post by obcbeatle »

I'm using the following php code to populate a web page with hyperlinks via a mysql db:

/* <?php
$con = mysql_connect("localhost","uid","pw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("mydb", $con);

$result = mysql_query("SELECT link
FROM tbllinkcat, tbllinks
WHERE tbllinkcat.catid = tbllinks.catid
AND tbllinkcat.catid=1;");

while($row = mysql_fetch_array($result))
{
echo "<ul>";
echo "<li>" . $row['link'] . "</li>";
echo "</ul>";
}
mysql_close($con);
?>
*/

Although the above code works fine when embedded in one web page, it is not a very efficient way of using mysql/php. What I REALLY want to do is populate ALL my web site web pages with links stored in mysql. I've done this with Dreamweaver/MySQL/IIS but I would really like figure this out using Apache/MySQL/PHP. I've tried googling and searched the mysql and php docs, but I've come up empty so far. If someone could kindly point me in the right direction (url, or code example) it would be greatly appreciated. Thanks!
User avatar
Sekka
Forum Commoner
Posts: 91
Joined: Mon Feb 18, 2008 10:25 am
Location: Huddersfield, West Yorkshire, UK

Re: writing mysql data to multiple files on a web site with php

Post by Sekka »

Place that code in a PHP file and include it into any page you want the links?
obcbeatle
Forum Newbie
Posts: 5
Joined: Fri Mar 07, 2008 9:21 am

Re: writing mysql data to multiple files on a web site with php

Post by obcbeatle »

Thank you for the reply. The include() function indeed was what I was looking for but wasn't aware of, although it appears that the require() function is preferred. Thus /*<?php require("links.php"); ?>*/ in every web page I want the links does the trick! I wonder if there is be a way though for writing mysql data to files w/o having to include the php code in every file? Like pre-populating a mysql table with the web page file names and then populating those files with the hyperlinks data. But that would probably take just as long as using the require() function above :) Thanks again for the reply!
Post Reply