One Class Two Functions Display at same time?
Posted: Sat Aug 20, 2005 8:00 am
Let me explain the issue I am facing before I show the code.
I have create a class to hold all of my main Display News Type Functions.
The question comes from two functions I am trying to get to work
together if possible.
First Function Grabs and Displays One random news article
from the database.
Second function paginates so that you can choose to view
with Previous and Next links.
I want to display both the Random News Link
above the Previous and Next links options
on same page.
The problem comes from each function handling a seperate
DB query to grab the correct type of info from the DB.
The first one only pulls ONE random article while the secone one
pulls One ordered article.
Of course, trying to use both on same page at same time results
in two News articles showing.
How can i make it so that it can tell the difference between
the two, and so that I can still display the
Random Previous/Next function and each doing the correct thing?
I am thinking it would be done by combining the functions into one
but not sure how to create the difference between the links to make
an IF statement ....
I am hoping people who read this can understand what I am
trying to attempt
Here's the two functions.....
I have create a class to hold all of my main Display News Type Functions.
The question comes from two functions I am trying to get to work
together if possible.
First Function Grabs and Displays One random news article
from the database.
Second function paginates so that you can choose to view
with Previous and Next links.
I want to display both the Random News Link
above the Previous and Next links options
on same page.
The problem comes from each function handling a seperate
DB query to grab the correct type of info from the DB.
The first one only pulls ONE random article while the secone one
pulls One ordered article.
Of course, trying to use both on same page at same time results
in two News articles showing.
How can i make it so that it can tell the difference between
the two, and so that I can still display the
Random Previous/Next function and each doing the correct thing?
I am thinking it would be done by combining the functions into one
but not sure how to create the difference between the links to make
an IF statement ....
I am hoping people who read this can understand what I am
trying to attempt
Here's the two functions.....
Code: Select all
class ShowNews {
//Shows One Random News Entry
function one_random_news_entry()
{
$result = mysql_unbuffered_query("SELECT * FROM news ORDER BY RAND() LIMIT 1");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$newposts = array ( $row['name'] => "Name", $row['lova'] => "Past Loves", $row['news'] => "Bash" );
foreach ( $newposts as $postfield => $postinput )
{
echo "<b>$postinput:</b> $postfield<br>";
}
echo "<p> </p>";
}
}
}
class NewsPagination extends ShowNews {
// Returns News Page Links
function NewsPage()
{
if(!isset($_GET['bash'])){
$bash = 1;
} else {
$bash = $_GET['bash'];
}
$max_results = 1;
$from = (($bash * $max_results) - $max_results);
$sql = mysql_query("SELECT * FROM news LIMIT $from, $max_results");
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM news"),0);
$total_bashs = ceil($total_results / $max_results);
if($bash > 1){
$prev = ($bash - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?bash=$prev\"><<-Previous</a> ";
}
if($bash < $total_bashs){
$next = ($bash + 1);
echo " <a href=\"".$_SERVER['PHP_SELF']."?bash=$next\">Next->></a>";
}
echo "</center><br><br><br><div id=test>";
while($row = mysql_fetch_array($sql)){
echo "Name: ". $row['name']."<br />";
echo "Past Loves: ". $row['lova']."<br />";
echo "Bash: ". $row['news']."<br />";
echo "<a href=./tell.php>Send</a>";
}
}
}