MySQLi的问题,请帮忙! [英] Problem with MySQLi, Please help!
问题描述
我的网站上有一个简单的私人消息系统..系统运行得非常好。但唯一的问题是,我收到消息时只能看到一条消息。那是因为我评论了一些代码。现在我知道MySQLi和PDO都有不同的编码方式..我在这里寻找MySQLi。
这是我的代码。基本上我想要注释掉的代码部分实际工作。我做错了吗?
I have a simple Private message system in my website.. The system works extremely well.. The only problem, however, is that I can only see one message when I received the message. And that is because I commented out some code. Now I know that MySQLi and PDO all have different ways of coding.. I''m looking for MySQLi here.
This is my code. Basically I want the parts of code that is commented out, to actually work. Am I doing something wrong?
function getMessages($user) {
$hostname = "localhost";
$username = "";
$db_password = "";
$db_name = "tsn_database";
$mysqli = @new mysqli($hostname, $username, $db_password, $db_name);
if(mysqli_connect_errno()) {
echo "Unable to connect";
} else {
$statement = $mysqli->prepare("SELECT * FROM messages WHERE sent_to='$user'");
$statement->execute();
$statement->bind_result($id, $date_sent, $sent_by, $sent_to, $message, $sent_by_delete, $sent_to_delete);
$statement->fetch();
$statement->close();
//if($mysqli->affected_rows > 0) {
//while($row = $mysqli->fetch_assoc($result)) {
global $result;
$result = 'From: '. $sent_by .'<br/>'
.'Date Received: '. $date_sent .'<br/>'
.'<hr/>'
. $message . '<br/><br/>'
.'<a href="?cmd=delete&id='.$id.'">Delete Message</a>';
//}
//} else {
//global $result;
//$result = "No Messages!";
//}
// return;
}
}
就像我说的那样..检索消息并将其显示给用户没有任何问题。它只是我只能显示一条消息而只显示有史以来发送的第一条消息。我想立刻显示所有消息..我修改了一段原始代码,使用了
Like I said.. There is nothing wrong with retrieving the messages and displaying it to the user. Its just that I can only display one message and only the first message ever sent. and I want to show all messages at once.. I have modified an original piece of code which used the
if (mysql_affected_rows > 0)
所以也许我只是使用了错误的代码?
提前致谢,
Chris
so maybe I am just using wrong code?
Thanks in advance,
Chris
推荐答案
user){
user) {
hostname = 本地主机 跨度>;
hostname = "localhost";
用户名 = 跨度>;
username = "";
这篇关于MySQLi的问题,请帮忙!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!