Jump to content

Billbonic

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Billbonic's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi guys, I've only recently starting learning php and I've been trying to understand the following code from a tutorial(which unforutnatly doesn't decribe this section of code) due to my born ignorance on the subject I would really appreciate some help on demystifying the source below: i really haven't a clue how it works: Thanks in advance for any replies - much appreciated. ------------------------------------------------------- <?php include_once("include/db_connection.php"); $initStartLimit = 0; $limitPerPage = 10; $startLimit = $_REQUEST['startLimit']; $numberOfRows = $_REQUEST['rows']; $sortBy = $_REQUEST['sortBy']; $sortOrder = $_REQUEST['sortOrder']; if ($startLimit=="") { $startLimit = $initStartLimit; } if ($numberOfRows=="") { $numberOfRows = $limitPerPage; } if ($sortOrder=="") { $sortOrder = "DESC"; } if ($sortOrder == "DESC") { $newSortOrder = "ASC"; } else { $newSortOrder = "DESC"; } $limitQuery = " LIMIT ".$startLimit.",".$numberOfRows; $nextStartLimit = $startLimit + $limitPerPage; $previousStartLimit = $startLimit - $limitPerPage; if ($sortBy!="") { $orderByQuery = " ORDER BY ".$sortBy." ".$sortOrder; } $sql = "SELECT * FROM customers".$orderByQuery.$limitQuery; echo $sql."<br>"; $result = MYSQL_QUERY($sql); $numberOfRows = MYSQL_NUM_ROWS($result); if ($numberOfRows==0) { ?> Sorry. No records found !! <? } else if ($numberOfRows>0) { $i=0; ?> <br> <? if ($_REQUEST['startLimit'] != "") { ?> <a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $previousStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Previous <? echo $limitPerPage; ?> Results</a>.... <? } ?> <? if ($numberOfRows == $limitPerPage) { ?> <a href="<? echo $_SERVER['PHP_SELF']; ?>?startLimit=<? echo $nextStartLimit; ?>&limitPerPage=<? echo $limitPerPage; ?>&sortBy=<? echo $sortBy; ?>&sortOrder=<? echo $sortOrder; ?>">Next <? echo $limitPerPage; ?> Results</a> <? } ?> <br><br> <TABLE CELLSPACING="0" CELLPADDING="3" BORDER="0" WIDTH="100%"> <TR><TD> <a href="<? echo $PHP_SELF; ?>?sortBy=customer_id&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>"> <B>Customer_id</B> </a> </TD><TD> <a href="<? echo $PHP_SELF; ?>?sortBy=fname&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>"> <B>Fname</B> </a> </TD><TD> <a href="<? echo $PHP_SELF; ?>?sortBy=mname&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>"> <B>Mname</B> </a> </TD><TD> <a href="<? echo $PHP_SELF; ?>?sortBy=lname&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>"> <B>Lname</B> </a> </TD><TD> <a href="<? echo $PHP_SELF; ?>?sortBy=company&sortOrder=<? echo $newSortOrder; ?>&startLimit=<? echo $startLimit; ?>&rows=<? echo $limitPerPage; ?>"> <B>Company</B> </a> </TD> etc...... for the rest of the column names like Address, City, State, Country etc... -------------------------------------------------------
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.