Is it possible to call a function via a URL?
I have the following code and what I want to be able to do is call the NewsList function via a URL.
The reason being I want to merge two php files I have created, one shows a listing of all news articles and another which shows the article detail. So the idea is when a user initially goes to the file it loads the NewsList function, and when they click on a record it will lod a ShowDetail function. (Not created yet!)
At the minute I am struggling to even call the ShowList function from the URL bar. Am I completly on the wrong track here?
Code: Select all
<?php
OpenConnection();
echo "this is a test line";
function OpenConnection()
{
Global $dbconn;
Global $result;
$dbconn = mysql_connect("localhost", "user", "password");
$result = mysql_select_db("database", $dbconn);
if ( $result == false)
{
echo mysql_error();
}
}
function NewsList()
{
$sql = "Select sid, title, cdate from table_news order by cdate desc";
$result = mysql_query( $sql );
if ( $result != false )
{
while ( $data = mysql_fetch_assoc( $result ) )
{
echo "<table width="80%" border="0" cellspacing="0" cellpadding="0">";
echo "<tr>" ;
echo "<td width="70%"><b><a href="news_detail.php?id=".$dataї'sid']."">".$dataї'title']."</a></b></td>";
echo "<td width="30%">$dataїcdate]</td>";
echo "</tr>";
echo "</table>";
}
} else {
echo mysql_error();
}
}
?>