我正在尝试从我的MySQL数据库中获取一些名为“opskriftreg”的信息,我希望它能将其打印出来,基本上它必须从我的数据库中检索已经创建的2x食谱,并相应地使用食谱列出它们“标题“首先”描述“
这是我的代码,如果这段代码是bollocks,如果有人能给我一个更好的例子,我会很高兴:
<?php
$mysqli = new mysqli ("localhost","root","","opskriftreg");
// Make a MySQL Connection
if (isset($_POST['title']) && isset($_POST['description']))
{
$username= $_POST['title'];
$password= $_POST['description'];
$query = "SELECT *
FROM opskriftreg
WHERE title = '".mysql_real_escape_string($title)."'
AND description = '".mysql_real_escape_string($description)."'";
$result = mysql_fetch_array(mysql_query($query));
# ...
}
else
{
return NULL;
}
?>
提前谢谢: - )
编辑:
代码更改为以下内容 - 收到空白页面,其中不返回任何内容或打印:
<?php
$mysqli = new mysqli("localhost", "root", "", "opskriftreg");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT title, description FROM opskriftreg ORDER by id DESC LIMIT 50,5";
if ($result = $mysqli->query($query)) {
/* fetch object array */
while ($row = $result->fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
/* free result set */
$result->close();
}
/* close connection */
$mysqli->close();
?>
答案 0 :(得分:0)
答案 1 :(得分:0)
试试这个,寻找我所做的改变。
<?php
$mysqli = new mysqli("localhost", "root", "", "opskriftreg");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT title, description FROM opskriftreg ORDER by id DESC";
$statement = $mysqli->prepare($query);
$statement->execute();
$results = $statement->get_result();
while ($result = $results->fetch_assoc()) {
printf ("%s (%s)\n", $result['title'], $result['description']);
}
/* close connection */
$mysqli->close();
?>