Strange Issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rmenard
Forum Newbie
Posts: 1
Joined: Wed Dec 02, 2009 12:58 pm

Strange Issue

Post by rmenard »

What seems to be happening is this:

Page buttons are in place on all except when page=0 or page=2.

On page=0 or page=2, the buttons are found within the table that the news in being displayed. I'm not sure of the cause

Code: Select all

 
<?
    $server = 'xxxxxxx';
    $username = 'xxxxxxx';
    $password = 'xxxxxxx';
    $db = 'moneyhungry';
    $table = 'news';
    
    mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($db) or die(mysql_error()); 
    if($_GET["cmd"]=="read" || $_POST["cmd"]=="read")
    {
 
        if (!isset($_POST["submit"]))
        {
            $id = $_GET["id"];
            $sql = "SELECT id,title,date,news FROM news WHERE id=$id";
            $result = mysql_query($sql);        
            $myrow = mysql_fetch_array($result);
        ?>
            <div class="newsFull">
                <font size='4'><u><b><?php echo $myrow["title"] ?></b></u></font>
                <br>
                <i><?php echo $myrow["date"] ?></i>
                <br>
                <?php echo $myrow["news"] ?>
            </div>
                                               
    <? } } else { 
        ?>
            
                
                
<?
    $server = 'xxxxxxx';
    $username = 'xxxxxxx';
    $password = 'xxxxxxx';
    $db = 'moneyhungry';
    $table = 'news';
        
    mysql_connect($server, $username, $password) or die(mysql_error());
    mysql_select_db($db) or die(mysql_error()); 
    
    $sql2 = "SELECT * FROM $table order by ID desc limit 10";
    $result2 = mysql_query($sql2);  
    
    $counter = mysql_query("select * from $table")
    or die ("Could not read data because ".mysql_error());
    
    if (mysql_num_rows($result2)) {
    ?>
<br><br>
 
<?
print "<table cellspacing='15' border='0' style='font-family: Arial; text-align: left; width: 900px; height: 4210px; color: #FFFFFF; font-size: 12px; position: absolute; left: 50%; margin-left: -425px; top: 560px; overflow: auto; z-index: 9;'><tr align='center'>";
$x = '0';
$rec_limit = 10;
 
$sql = "SELECT count(ID) FROM $table ";
$retval = mysql_query( $sql );
if(! $retval )
{
  die('Could not get data: ' . mysql_error());
}
$row = mysql_fetch_array($retval, MYSQL_NUM );
$rec_count = $row[0];
 
if( isset($_GET{'page'} ) )
{
   $page = $_GET{'page'} + 1;
   $offset = $rec_limit * $page ;
}
else
{
   $page = 0;
   $offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
                        
$sql = "SELECT ID, Date, Title, news_brief, News, video ".
"FROM $table ". 
"ORDER by ID desc ".
"LIMIT $offset, $rec_limit";
    
$retval = mysql_query( $sql );
if(! $retval )
{
    die('Could not get data: ' . mysql_error());
}
 
while ($qry = mysql_fetch_array($retval)) {     
    $title=$qry["Title"];
    $title = ucwords($title);
    $id=$qry["ID"];
    $date=$qry["Date"];
    $news=$qry["News"];
    $newsbrief=$qry["news_brief"];
    $newsbrief = preg_replace("/[\r\n]+/", "<br><br>", $newsbrief);
        
    $limit = 600;
                            
    print "<a href='../news/view/index.php?cmd=read&id=$id'><font size='4'><b>$title</b></font></a>\n";
    print "<br>\n";
    print "<i>$date</i>";
    print "<input type='hidden' name='id' value='$id'>";
                    
    if (strlen($newsbrief) > $limit) {
        $new = substr($newsbrief, 0, strrpos(substr($newsbrief, 0, $limit), ' ')) . '...';
        $new = str_replace('alt="Photobucket"', 'width="25%"', $new);
        print "<br>
        $new\n";
        print "<br>(<u><a href='../news/view/index.php?cmd=read&id=$id'>Read More</a></u>)<br><br><br><br>\n";
    } else {
        $new = preg_replace("/[\r\n]+/", "<br />", $newsbrief);
        $new = str_replace('alt="Photobucket"', 'width="25%"', $new);
        print "<br>$new\n";
        print "<br><br><br><br>\n";
    }
}                           
?>
                        
    <?
    }
        print "</tr></table>";
    }
 
    if(isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID']) != '')) {               
        if( $page > 0 )
        {
           $last = $page - 2;
           echo "<div style='position: absolute; left: 50%; margin-left: -130px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><a href=\"$_PHP_SELF?page=$last\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
           echo "<div style='position: absolute; left: 50%; margin-left: 95px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
         else if( $page == 0 )
        {
           echo "<div style='position: absolute; left: 50%; margin-left: 95px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
        else if( $left_rec < $rec_limit )
        {
           $last = $page - 2;
           echo "<div style='position: absolute; left: 50%; margin-left: -130px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$last\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
        
        if($_GET["cmd"]=="download" || $_POST["cmd"]=="download")
        {
            if (!isset($_POST["submit"]))
            {
                $id = $_GET["id"];
                $url = $_GET["url"];
                $sql = "SELECT * FROM $table WHERE ID=$id";
                $addTotal = "UPDATE $table SET total = total+1 WHERE ID = '$id'";
                $add=mysql_query($addTotal);
                
                header('Refresh: 0; url=$url');
                exit();
            }
        }
    } else {
        if( $page > 0 )
        {
           $last = $page - 2;
           echo "<div style='position: absolute; left: 50%; margin-left: -130px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><a href=\"$_PHP_SELF?page=$last\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
           echo "<div style='position: absolute; left: 50%; margin-left: 95px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
        else if( $page == 0 )
        {
           echo "<div style='position: absolute; left: 50%; margin-left: 95px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$page\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
        else if( $left_rec < $rec_limit )
        {
           $last = $page - 2;
           echo "<div style='position: absolute; left: 50%; margin-left: -130px; top: 4825px; z-index: 3;'><a href=\"$_PHP_SELF?page=$last\"><img src='../images/invlink.gif' height='10' width='30'></a></div>";
        }
    }
                        
    mysql_close();
 
?>
 
 
The page buttons refer to the buttons which allow users to go to the next or previous pages of information.

To see this live:
http://moneyhungryradio.com/news
Post Reply