Hi,
I am a php and myQSL newbie but have somethign that's causing me a bit of trouble:
I have excluded the database connection lines but the code at the end of the page is the basis for my "develop_news_table.php" file. It searches my database of news articles for news linked to a company's name (provided in the $test_string) by seeing if it is any of the 4 company columns and making an a array of the rows that do and ordering them by date ($result).
It then prints them out.
I will have many different pages for each company and the coding for the news clippets section will be the same in each case with only the name of the company changing. I would prefer to have the company page as a html that then includes the results from develop_table.php in one of the cells. This way I can change the format of the develop_table code only once rather than for every page.
So I need the html page to send a variable (company name) to the php file which then uses that as $test_string (instead of the specific name I currently have in the code below).
Ideally I would like $result to be sent back to the html file so I can format things nicely but I dont think that is possible. So instead I would just like to embed what the php file does on the html cell and do this all on the html page.
I dont really want to have to rename all my files php and this will also affect exisiting dreamweaver templates.
If making each company page a php is the only option, how can I still refer to an external php file with the company name and then return the data to the original page as the array which can then be formatted (or also do all the formatting/printing in the external file but while on the company's main php page).
I hope this is clear, I want to have an external php file do something but not by loading a new page in the browser. cheers, here is the code:
<?
$test_string = "iogen";
$query = sprintf("SELECT * FROM news_articles WHERE company1='%s' OR company2='%s' OR company3='%s' OR company4='%s'ORDER BY date DESC", mysql_real_escape_string($test_string), mysql_real_escape_string($test_string), mysql_real_escape_string($test_string), mysql_real_escape_string($test_string));
$result = mysql_query($query);
if (empty($result))
{ print"No Data"; }
else
{
if (mysql_num_rows($result) == 0)
{
echo "<br />" . "
There are currently no news articles available" . "<br />" ;
exit;
}
while ($row = mysql_fetch_assoc($result))
{
echo $row['date'] . "<br />";
echo $row['title'];
echo $row['company1'];
print "\r\n";
}
}
?>