Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Totalling the pages in next/previous function 1

Status
Not open for further replies.

sinbadly

Technical User
Mar 16, 2006
126
GB
This code tells website visitors how many articles are available for the month -

$result = @mysql_query("SELECT COUNT(*) AS t FROM junestu");
while( $row = mysql_fetch_array($result))
echo 'We have <font color="#FF9933"><b>' . $row["t"] . ' </b> </font> bulletins for June.';

And this code sets the number of pages for the next and previous functions -

echo '<div class="Next">';
$next = $_GET['id'] + 1;
$previous = $_GET['id'] - 1;
$total = 5;

How can I use the result of the top function to set the $total in the next/previous function, please, Experts?
 
answer: assign the number of articles a variable in the global scope

Code:
$result = @mysql_query("SELECT COUNT(*) AS t FROM junestu");

$GLOBALS['t'] = mysql_result($result,0,0); //changed
 
    echo 'We have <font color="#FF9933"><b>' . $t . ' </b> </font> bulletins for June.';

And this code sets the number of pages for the next and previous functions -

echo '<div class="Next">';        
            $next = $_GET['id'] + 1;
            $previous = $_GET['id'] - 1;
            $total = $GLOBALS['t'];
 
Hi Justin and many thanks. Will play with it tonight. Is a global declared at the top of the code? Well, I will be experimenting, so I guess I will find out. Cheers
paul
 
hello - you can add to the $GLOBALS superglobal from anywhere in your code (inside a function, object or wherever) and have it globalls available.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top