What's wrong here?

Codes here !

Moderators: egami, macek, gesf

Post Reply
Bar2aYunie
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Dec 17, 2017 8:25 am

Sun Dec 17, 2017 8:28 am

Hello,

Does anybody know what's wrong with this code? It used to work before and I made no changes. It says the code is old....

Hope you can help me.

Thank you!

Yurie

Code: Select all

<?php
        /**
        * options
         */

$id = $_GET['id'];

$maxcol = 2;
$result = mysql_query("SELECT * FROM database_options order by name desc") or die (mysql_error());
$count = mysql_num_rows($result);
$rows = ceil($count/$maxcol);
echo "<table>";

$limit = 200;
$table = 'options';
//get requested page
$page = empty($_GET['page']) ? 1 : (int) $_GET['page'];
//calculate offset
$offset = ($page - 1) * $limit;

//construct query
$query = "Select SQL_CALC_FOUND_ROWS * from $table order by name desc LIMIT $limit OFFSET $offset";

//execute query
$result = mysql_query($query) or die (mysql_error());
$cResult = mysql_query("Select found_rows()") or die(mysql_error());
list($count) = mysql_fetch_array($cResult, MYSQL_NUM);

$pageNavBar = getPages($limit, $count, $page);
//start the output
echo <<<HTML
<style type="text/css">
/*style links */
.pageNav a {text-decoration:none; cursor:crosshair; color: #131d31;}
.pageNav a:visited {text-decoration:none; color: #131d31;}
/*make the page numbering smaller generally */
.pageNav{ font-size:smaller;}
.page{ border: thin dotted #060409; background-color:#fdffeb;}
.navi{ padding: 5px; margin: 2px; width: 2em;}
.prev{}
.last{ background-color:;}
.first{ background-color:;}
.next{}
.active {backround-color:grey; color:red;}
.select select {}
.table {font-family: verdana; font-size: 12px;}



</style>
<table width="100%" border="0" rules="groups" table class="table">
<thead>
</thead>
<tbody>
HTML;
while ($row = mysql_fetch_assoc($result)){
    echo <<<HTML

<tr>
    <td align="left" width="50%"> <a href="{$row['link']}">{$row['optionname']}</a></td>
HTML;
    $row = mysql_fetch_assoc($result);
    if (!$row){
      echo "<td>&nbsp;</td><td>&nbsp;</td>";
    } else {
    echo <<<HTML
    <td align="left" width="50%"> <a href="{$row['link']}">{$row['optionname']}</a></td>
HTML;
} //end if
   echo "</tr>";
} //end while

echo <<<HTML
</tbody>
<tfoot>
<tr>
    <p><th colspan="4">
        $pageNavBar
    </th>
</tr>
</tfoot>
</table>
HTML;

function getPages($limit, $count, $page){
    //put the url into a variable
    $s = "http://" . $_SERVER['HTTP_HOST'] .'/'.  ltrim($_SERVER["SCRIPT_NAME"] ,'/');
    //calculate the number of pages needed
    $nPages = ceil($count/$limit);
    //do the first/last prev/next buttons
    $first = <<<HTML
<span class="first navi">
    <a href="$s?page=1"><<<</a>
</span>
HTML;
    $last = <<<HTML
<span class="last navi">
    <a href="$s?page=$nPages">>>></a>
</span>
HTML;
    if ($page  > 1) {
        $p = $page - 1;
        $prev = <<<HTML
    <span class="next navi">
        <a href="$s?page=$p"><</a>
    </span>
HTML;
    } else {
        $prev = '&nbsp;';
        $first = '&nbsp;';
    }
    if ($page < $nPages) {
        $p = $page + 1;
        $next = <<<HTML
    <span class="next navi">
        <a href="$s?page=$p">></a>
    </span>
HTML;
    } else {
        $next = '&nbsp;';
        $last = '&nbsp;';
    }

    //now construct the pages
    //if more than 10 then use a select
    if ($nPages > 10){
        $output = <<<HTMLJS
<span class="navi select">
    <select name="page" onchange="window.location='{$s}?page=' + this.options[this.selectedIndex].value;">
HTMLJS;

        for ($p=1; $p <=$nPages; $p++){
            $output .= "<option value=\"$p\">$p</option>";
        }
        $output .= '</select></span>';
    } else {
        $output = '';
        for ($p=1; $p<=$nPages; $p++){
            $active = ($p == $page) ? 'active' : '';
            $output .= "<span class=\"navi page {$active}\"><a href=\"$s?page=$p\">$p</a></span>";
        }
    }
    return '<div class="pageNav">' . $first . $prev. $output . $next .  $last . '</div>';
}


?>

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 755
Joined: Mon Feb 22, 2016 5:52 pm

Sun Dec 17, 2017 4:12 pm

What version of PHP are you running?

I suspect that it has been upgraded to PHP 7, if so you will have to re-code your scripts since the database function calls you are using have been deprecated for several years and have now been removed from PHP 7.

Bar2aYunie
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Dec 17, 2017 8:25 am

Sun Dec 17, 2017 4:18 pm

Yes indeed, it's the latest version. So how can those be rewritten? I tried several things, but it constantly gives me several errors and I have no idea which changes are good and which ones aren't.

Also, the NaveBar is no longer needed (I want all of the info from the database displayed on one page), but I also cannot seem to get that thing out since it no longer works so I can't test it.

I am actually just trying to create a table which several items from my database displayed in a 3-column table. Can you help out?

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 755
Joined: Mon Feb 22, 2016 5:52 pm

Sun Dec 17, 2017 7:05 pm

I assume from your response that you didn't read the link I provided, I'm afraid that it's going to involve a lot of reading and re-writing on your part. I'm willing to help, but not willing to do all the work for you - if you want someone to do all the translation for you you might have to consider paying someone, but do your research before employing someone, there are a lot of sharks out there.

Bar2aYunie
New php-forum User
New php-forum User
Posts: 3
Joined: Sun Dec 17, 2017 8:25 am

Wed Dec 20, 2017 11:46 am

Oh I'm sorry, I didn't see the link. I will definitely look into it (the link) and of course I don't expect you to write it for me without me doing anything.

I had no idea that it would be so much work, I thought it would just need a simple modification done within seconds.

Lemme try to puzzle something together. Thank you very much!

Post Reply