Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.20/5 (2 votes)
See more:
hey, can someone please explain what this code does. am not entirely sure as i am new to PHP and mySql.Thanks


If someone could comment the code, ( i know that is asking for a lot) I would be SO HAPPY!, have a nice day


PHP
$pp=4;

if (empty($_GET['page_number']))
{
        //default page/total = 1
        $pg=0;
        //get total num of pages
        $query_get_all="SELECT * FROM pictures order by id ASC";
        $res_get_all=mysql_query($query_get_all) or die(mysql_error());
        $get_all=mysql_num_rows($res_get_all);

        $pgtotal=$get_all;
        if ( $pgtotal%$pp==0) {
            $pgtotal/=$pp;
            $pgtotal--;
        }
        else {
            $pgtotal/=$pp; //$pgtotal++;
            $pgtotal=floor($pgtotal);
        }

}
else
{
        $pg=intval(strip_tags($_GET['page_number']))-1;
        //get total num of pages

        $query_get_all="SELECT * FROM pictures order by id ASC";
        $res_get_all=mysql_query($query_get_all) or die(mysql_error());
        $get_all=mysql_num_rows($res_get_all);

        $pgtotal=$get_all;
        if ( $pgtotal%$pp==0) {
            $pgtotal/=$pp;
            $pgtotal--;
        }
        else {
            $pgtotal/=$pp; //$pgtotal++;
            $pgtotal=floor($pgtotal);
        }
}

    $lim_inf=$pg*$pp;
    $lim_sup=$lim_inf+$pp;

    $select_picture = "SELECT * FROM pictures  ORDER BY id ASC LIMIT $lim_inf,$pp ";

    $result_select_picture=mysql_query($select_picture) or die(mysql_error());
    $noproducts = mysql_num_rows($result_select_picture);
?>
Posted
Comments
Sergey Alexandrovich Kryukov 5-May-14 14:51pm    
Strictly speaking, such questions make no sense, because the real intent of the code author in not preserved it the code itself. Also, looking at the code who does who-knows-what is not a productive way of doing software engineering. If you show your own code having some problems you can clearly explain, we will gladly help you.
—SA
Paulo Augusto Kunzel 5-May-14 14:52pm    
It shows you how to not: code, name variables and write comment.
If you are new to php, please refer to http://www.w3schools.com/php/default.asp and http://www.codecademy.com/tracks/php
Sergey Alexandrovich Kryukov 5-May-14 19:01pm    
Great point. The sad thing is: many our inquirers, as this one, try to learn programming on such code.
—SA

1 solution

No. It is not going to happen.

I would suggest that you go back to where you got that from and ask them to do it - because if you can't understand it, then honestly you shouldn't be trying to to use it...because it isn't going to do exactly what you want, and you won't know how to modify it anyway.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900