![ישן](https://static.fresh.co.il/images/vBulletin/statusicon/post_old.gif)
12-12-2004, 13:19
|
|
|
חבר מתאריך: 21.06.02
הודעות: 517
|
|
האם הקוד הבא לחילוק דפים הוא יעיל?
שלום לכולם![Smile](images/smilies/smile.gif)
השאלה שאני שואל האם הקוד הבא הוא יעיל לשליפת נתונים ממסד נתונים והצגתם כך שכל דף הוא יציג שישה נתונים.
אני שואל את השאלה בגלל שריבוי משפטי ה-If והלולאה על לולאה.
הודה לכם אם תענו ותראו לי כיצד לייעל את הדף.
קוד PHP:
<table width="100%"> <tr><td> <?php include ("config.php"); mysql_pconnect( "localhost", "$username", "$password") or die( "Unable to connect to SQL server"); mysql_select_db( "$db_name") or die( "Unable to select database"); $query = mysql_query("SELECT count(*) as total FROM `members`") or die(mysql_error()); $row = mysql_fetch_array($query,MYSQL_ASSOC); $numrows = $row['total']; if (empty($offset)) { $offset=0; } $query = "SELECT user, pass, email, id FROM members order by id DESC limit $offset,$limit"; $result = mysql_query ($query) or die ("query 2 failed"); while ($row = mysql_fetch_row ($result)) { for ($i = 0; $i < mysql_num_fields ($result); $i++) { if ($i > 0) print (" "); if ($i == 0){ print "<b>Name: </b>"; } else if ($i == 1){ print "<b>Date: </b>"; } else if ($i == 2){ print "<b>Email: </b>"; } else{ print "<b>Comment:</b> "; } print ($row[$i]); } print " <center><hr></center>"; print ("<P>"); } if ($offset >= 3) { $prevoffset = $offset - $limit; print "<a href=\"?offset=$prevoffset\">PREV</a> \n"; } $pages=intval($numrows/$limit); if ($pages < ($numrows/$limit)){ $pages=($pages + 1); } for ($i = 1; $i <= $pages; $i++) { $newoffset = $limit*($i-1); if ($newoffset == $offset) { print "$i \n"; } else { print "<a href=\"?offset=$newoffset\">$i</a> \n"; } } //show next if not last if (! ( ($offset/$limit) == ($pages - 1) ) && ($pages != 1) ) { $newoffset = $offset+$limit; print "<a href=\"?offset=$newoffset\">NEXT</a><p>\n"; } ?> </td></tr> </table> </body> </html>
|