gc40
04-01-2007, 05:35 AM
I have two while statements in a php script. However, the second one is not outputting the way it should.
When I test them individually, both work. Can anyone have a look at the code and tell me what I must edit to get both working together...
<?php
// Database Connection
include 'dbconnect.php';
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM Portfolio where `Website` = 1 ORDER BY `Title` LIMIT $from, $max_results");
while($onehome = mysql_fetch_array($sql))
{
//start of Tabs//
/////////////////
//Defining the Tab Labels; LinkName, ScreenShots, Additional Info
echo "<p align='left'></p><ul id='";
//Giving maintab a unique name by assinging PortfolioID infront of it.
echo $onehome['PortfolioID']."maintab' class='shadetabs'>";
//Defining the Link Tab's Uniqueness
echo "<li class='selected'><a href='#' rel='".$onehome['PortfolioID']."link'>".$onehome['Title']."</a></li>";
//Defining Uniqueness for ScreenShots Tab
echo "<li class=''><a href='#' rel='".$onehome['PortfolioID']."screenshot'>Screenshots</a></li>";
//Defing Uniqueness for Additional Info Tab
echo "<li class=''><a href='#' rel='".$onehome['PortfolioID']."status'>Additional Info.</a></li>";
echo "</ul>";
/////////////
//End of Tabs
}
//Javascript for Tab Content//
echo "<script type='text/javascript'>";
//Initialize every single tab contnet//
echo "initializetabcontent('";
while($onehome = mysql_fetch_array($sql))
{
echo $onehome['PortfolioID']."maintab', ";
}
echo ")";
echo "</script>";
//End of Javascript//
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Portfolio"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center><div class='pagination'>Page $page of $total_pages</div>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\" class='pagination'><< Previous </a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" class='pagination'> $i </a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\" class='pagination'> Next >></a>";
}
echo "</center><br>";
?>
When I test them individually, both work. Can anyone have a look at the code and tell me what I must edit to get both working together...
<?php
// Database Connection
include 'dbconnect.php';
// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page = 1;
} else {
$page = $_GET['page'];
}
// Define the number of results per page
$max_results = 10;
// Figure out the limit for the query based
// on the current page number.
$from = (($page * $max_results) - $max_results);
// Perform MySQL query on only the current page number's results
$sql = mysql_query("SELECT * FROM Portfolio where `Website` = 1 ORDER BY `Title` LIMIT $from, $max_results");
while($onehome = mysql_fetch_array($sql))
{
//start of Tabs//
/////////////////
//Defining the Tab Labels; LinkName, ScreenShots, Additional Info
echo "<p align='left'></p><ul id='";
//Giving maintab a unique name by assinging PortfolioID infront of it.
echo $onehome['PortfolioID']."maintab' class='shadetabs'>";
//Defining the Link Tab's Uniqueness
echo "<li class='selected'><a href='#' rel='".$onehome['PortfolioID']."link'>".$onehome['Title']."</a></li>";
//Defining Uniqueness for ScreenShots Tab
echo "<li class=''><a href='#' rel='".$onehome['PortfolioID']."screenshot'>Screenshots</a></li>";
//Defing Uniqueness for Additional Info Tab
echo "<li class=''><a href='#' rel='".$onehome['PortfolioID']."status'>Additional Info.</a></li>";
echo "</ul>";
/////////////
//End of Tabs
}
//Javascript for Tab Content//
echo "<script type='text/javascript'>";
//Initialize every single tab contnet//
echo "initializetabcontent('";
while($onehome = mysql_fetch_array($sql))
{
echo $onehome['PortfolioID']."maintab', ";
}
echo ")";
echo "</script>";
//End of Javascript//
// Figure out the total number of results in DB:
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM Portfolio"),0);
// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);
// Build Page Number Hyperlinks
echo "<center><div class='pagination'>Page $page of $total_pages</div>";
// Build Previous Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\" class='pagination'><< Previous </a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\" class='pagination'> $i </a> ";
}
}
// Build Next Link
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\" class='pagination'> Next >></a>";
}
echo "</center><br>";
?>