PHP while loop multiple conditions returning no data? -
i have php page returning data mysql table. decided add feature allow user set number of results want displayed, in case there thousands of records example.
here php code displays data:
while ($row = mysql_fetch_array($result) && ($row <= $noofresults)) { echo '<p class="display-date">' . $row['date'] . '</p><p class="display">' . $row['id'] . ' - ' . base64_decode( $row['packetdata']) . '</p>'; echo '<hr align="center" width="100%" />'; echo $noofresults; }
i hoping display data point user has selected. if user selects 10 results, $noofresults set 10, , fetch first 10 results database. displaying "-" , $noofresults variable (which desired @ point). syntax wrong or not correct method of going such problem?
thanks, got working limit, didn't think that.
can explain why downvoted, trying learn, write better questions in future, thanks.
the best way limited data database limit statement in query . assume query is
$result= "select * `mytable`";
just add limit statement in
$result= "select * `mytable` limit '$noofresults'";
then while loop
while ($row = mysql_fetch_array($result) ) { echo '<p class="display-date">' . $row['date'] . '</p><p class="display">' . $row['id'] . ' - ' . base64_decode( $row['packetdata']) . '</p>'; echo '<hr align="center" width="100%" />'; echo $noofresults; }
Comments
Post a Comment