i have been staring @ code long starting bleed together. let's couple things out of way:
- i low-moderate level sql user , still learning best ways accomplish queries , such
- i have been building php based quote-generator tool ties in sql database
now, here trying accomplish: have pagination results of quotes have been created status not "dead", "duplicate", or "signed" , id not equal 999 (because wanted quotes jump 1000 , did not build database correctly @ first)
here have accomplished: able create basic structure , works fine on page 1... goes sideways. thinking count(*) query, seems fine - functional, @ least:
$countqry = "select count(*) needsassessment id <> 999 , status <> 'dead' , status <> 'duplicate' , status <> 'signed'"; $countresult = $mysqli->query($countqry); while($rowq = mysqli_fetch_array($countresult)) { $totalrows = $rowq[0]; $each = ceil($totalrows/$limit); $where = "where id > 0"; if ($totalrows == 0) { echo "you have not created quotes."; } } $limit = 15; if (isset($_get['q']) && $_get['q'] !== "") { $offset = $_get['q']; } else { $offset = 0; } $query = "select * needsassessment $where $and , id <> 999 , not status = 'dead' , not status = 'duplicate' , not status = 'signed' order id desc limit $offset, $limit"; $result = $mysqli->query($query); $row_cnt = mysqli_num_rows($result); if ($row_cnt == 0) { echo "you have not created quotes."; die; } if (!isset($each)) { $each = $row_cnt/$limit; } if ($each > 1) { echo "<ul class='pagination'>"; for($i=1,$y=0;$i<=$each,$y<=($each-1);$i++,$y++) { echo "<li><a"; if ($offset == ($y*15)) {echo ' class="active"';} echo " href='?q=".($y*15)."'>$i</a></li>"; } echo "</ul>"; }
okay, here questions:
- i saw using php's mysqli_num_rows() wrong , should use sql's count(*). why? have different result or take longer?
- what going on page's 2 , 3? when row count says sees 15 rows showing. have records (i.e. status of "signed" or "dead") excluded list , thinking may have been issue, doesn't seem matter on first page.
- what difference - if there 1 - between "not" , "<>" checking records?
- if have suggestions or if have done blatantly wrong or inefficiently please let me know can correct :)
thanks make stack overflow awesome!
edit: there code missing:
if (!isset($sst)) { $where = ""; $sst = ""; $countqry = "select count(*) needsassessment id <> 999 , status <> 'dead' , status <> 'duplicate' , status <> 'signed'"; $countresult = $mysqli->query($countqry); while($rowq = mysqli_fetch_array($countresult)) { $totalrows = $rowq[0]; $each = ceil($totalrows/$limit); $where = "where id > 0"; if ($totalrows == 0) {echo "you have not created quotes.";} } } else { if ($option !== "*") { $where = "where ".$option." '%".$sst."%'"; } if ($option == "*") { $where = "where status '%".$sst."%' or title '%".$sst."%' or proptype '%".$sst."%' or pstype '%".$sst."%' or createdate '%".$sst."%'"; } $offset = 0; } if ($_session['admin'] >= 1) { $and = ""; } else { $and = "and creatorid = '".$_session['user']."'"; }
Comments
Post a Comment