gpt4 book ai didi

php - 使用SQL从mysql表中选择数据

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:44 24 4
gpt4 key购买 nike

我有一个网页,我希望用户在文本字段中输入任何数据,因此它应该在mysql表中检查是否类别类似于用户输入的文本,然后在此处显示结果是我的php页面代码:

   <?php
$host = "surveyipad.db.6420177.hostedresource.com";
$user = "";
$pass = "";
$database ="surveyipad";


$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

if (!function_exists('json_encode'))
{
function json_encode($a=false)
{
if (is_null($a)) return 'null';
if ($a === false) return 'false';
if ($a === true) return 'true';
if (is_scalar($a))
{
if (is_float($a))
{
// Always use "." for floats.
return floatval(str_replace(",", ".", strval($a)));
}

if (is_string($a))
{
static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
}
else
return $a;
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a))
{
if (key($a) !== $i)
{
$isList = false;
break;
}
}
$result = array();
if ($isList)
{
foreach ($a as $v) $result[] = json_encode($v);
return '[' . join(',', $result) . ']';
}
else
{
foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v);
return '{' . join(',', $result) . '}';
}
}
}


$flu=$_POST['searchCode'];


$query =mysql_query("SELECT * From catalog_Master WHERE category_Title LIKE '%".$flu."%' ");
$rows = array();
while($row = mysql_fetch_assoc($query)) {
$rows[] = $row;
}

echo json_encode($rows);
?>


html页面代码

  <HTML>
<head>API TESTING</head>
<body>
<form action="searchCatalog.php" method="post">
<input type="text" value="enter category"/>
<input type="submit" value="Enter To Get Value"/>
</form>

</body>
</HTML>


它显示如下错误

 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/pah_brd_v1/productivo/searchCatalog.php on line 63

最佳答案

可能是您的查询有问题,有必要查看查询和mysql错误信息

请尝试此并发布输出

$query =mysql_query("SELECT * From catalog_Master WHERE category_Title LIKE '%".$flu."%' ") or die ("query error ".mysql_error());

关于php - 使用SQL从mysql表中选择数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16099173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com