我想弄清楚下面我的mysqli代碼有什麼問題。數據絕對在表格中。我有2個問題:這個mysqli查詢有什麼問題?
- 爲什麼不給我任何結果?
我可以在單獨的php文件中回顯
<table></table>
部分,如果是的話,我會如何調用$name,$partner,$cell
等?<?php $mysqli = new mysqli($host, $uname, $pword, $db); if ($mysqli->connect_errno) { echo "Connection failed: %s\n", $mysqli->connect_error; exit(); } $query = ("SELECT * FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer/Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC"); $result = $mysqli->query($query); while ($row = $result->fetch_array()) { $space = (!empty($row['firstname']) && !empty($row['lastname'])) ? ' ' : ''; $name = $row['firstname'].$space.$row['lastname']; $partner = $row['spousefirst']; $cell = (!empty($row['phonecell'])) ? " {$row['phonecell']} (cell)" : ''; $email = (!empty($row['email'])) ? " {$row['email']} (email)" : ''; $ID = $row['ID']; echo'<table> <tbody> <tr> <td><input type="checkbox" name="" id="" value="<? echo $ID; ?>"></td> <td><a href="/backend/leads/view/?ID=<? echo $ID; ?> "><strong><? echo $name; ?></strong></a></td> <td><a href="/backend/leads/view/?ID=<? echo $ID; ?> "><? echo $partner; ?></a></td> <td><? echo $phonecell; ?></td> <td><a href="mailto:<? echo $email; ?>"><? echo $email; ?></a></td> <td><? echo date("M jS, g:i A", strtotime($date)); ?></td> <td><? echo $contacttype; ?></td> <td><? echo $agentassigned; ?></td> <td><? echo $leadstatus; ?></td> <td><a href="/backend/contacts/notes.php?ID=<? echo $ID; ?>">View </a>+ </td> <td><a href="/backend/contacts/todo.php?ID=<? echo $ID; ?>">View </a>+ </td> <td><a href="/backend/contacts/deletesuccess.php?ID=<? echo $ID; ?>">D</a></td> </tr> </tbody> </table>'; } ?>
編輯:
它顯示<table>
卻唯獨沒有給我的$名稱,$電子郵件... ECT值。
嘗試回顯錯誤。例如:'$ query =(「SELECT * FROM contacts WHERE contacttype IN('New','Buyer','Seller','Buyer/Seller','Investor')AND leadstatus ='New'ORDER BY date DESC」)或死(mysql_error);'看:http://forums.devarticles.com/mysql-development-50/mysql-where-in-function-2031.html –
你確定查詢結果什麼?您是否嘗試在MySQL命令行/ phpMyAdmin中執行? – CodeZombie
嘗試分解查詢並確保預期數據存在於表中。 – Usman