10-12-2004, 14:46
|
|
|
חבר מתאריך: 26.10.04
הודעות: 19
|
|
עזרה-While+MySql
קוד PHP:
<?php require('include/db_connect.php'); $page = (int) $_GET['page']; if($page>1000 || $page<1) $page=1; $per_page = 5; /* $start = ($page-1) * $per_page; */ $start = $page * $per_page - 10; $num_rows = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM news"),0); $query = mysql_query("SELECT * FROM news LIMIT $start, $per_page") or die(mysql_error()); /* $row = mysql_fetch_array($query, MYSQL_ASSOC); $total_num = $row['total']; */ echo " <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\"> <html dir=\"rtl\"> <head> <meta http-equiv=\"Content-Type\" content=\"text/html; charset=windows-1255\"> <link rel=\"stylesheet\" type=\"text/css\" href=\"include/defualt.css\"> <script src=\"include/defualt.js\" Language=\"Javascript\"></script> </head> <body> <font style=\"font-family: arial; font-size: 13;\"> <table width=\"75%\" border=\"0\"> "; while ( $inf = mysql_fetch_array($query, MYSQL_ASSOC)) { $name = $inf['name']; $full = $inf['full']; $date = $inf['date']; $mail = $inf['mail']; $id = $inf['id']; echo "<tr>" . "<td colspan=\"17\" rowspan=\"1\"><a href=\"mailto:$mail\">$name</a></td>" . "<td colspan=\"9\" rowspan=\"1\"><a href=\"http://www.icq.com/$id\">$id</a></td>" . "<td colspan=\"50\" rowspan=\"1\">$full</td>" . "<td colspan=\"4\" rowspan=\"1\">$date</td>" . "<td colspan=\"3\" rowspan=\"1\"><img src=\"http://web.icq.com/whitepages/online?icq=$id&img=5\"></td>"; } $a= $num_rows/$per_page; $total_pages = ceil($a); for($i = 1; $i <= $total_pages; $i++){ echo "<a href=\"?page=$i\">$i</a> "; } ?>
בקוד הזה אני נותן 2 פקודות לPhp:
1.יצירת לולאת while שתציג את התוצאות מהמסד.
2.יצירת לולאת for שתדפיס מעבר בין עמודים (עפ"י המידע במסד)
הבעיה שנוצרת לולאת for טובה אבל לא נוצרת לולאת while.
הערה:אם אני סוגר את התג <tr> אז גם לולאת הfor לא נוצרת.
|