在浏览帖子并使用 Google 之后,我想我已经掌握了答案的基本组成部分,尽管由于缺乏 MySQL 经验,我不完全确定如何将它们组合在一起。
---Edit Begin (2013/10/16@1110GMT--- 下面是代码当前的样子:
$username="username"; $password="password"; $database="database";
mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die(
"Unable to select database");
$needle = 'sdfsdf';
$checkUserID = mysql_query("SELECT * FROM order_option WHERE value LIKE '%$needle%' ");
if (!$checkUserID) {
die('Query failed to execute for some reason');
}
if (mysql_num_rows($checkUserId) > 0) {
echo "<p>User id exists already.</p>";
$user = mysql_fetch_array($checkUserId);
print_r($user); // the data returned from the query
}
mysql_close();
我想知道我是否误解了 MySQL,尽管我知道应该从这个 MySQL TRUNCATE TABLE 中提取查询order_option
;
INSERT INTO `order_option` (`order_option_id`, `order_id`, `order_product_id`, `product_option_id`, `product_option_value_id`, `name`, `value`, `type`) VALUES ('13', '2', '2', '237', '0', 'Additional Information', 'sdfsdf', 'textarea');
INSERT INTO `order_option` (`order_option_id`, `order_id`, `order_product_id`, `product_option_id`, `product_option_value_id`, `name`, `value`, `type`) VALUES ('14', '2', '2', '228', '0', 'Website', 'fsdfsd', 'text');
---编辑结束---
脚本如下:
$user="user"; $password="password"; $database="mydatabase";
mysql_connect(localhost,$user,$password);
@mysql_select_db($database) or die("Unable to select database");
$needle = 'sdfsdf';
$checkUserID = mysql_query("SELECT value from order_option WHERE value = '$needle'");
if (!$checkUserID) {
die('Query failed to execute for some reason');
}
if (mysql_num_rows($checkUserId) > 0) {
echo "User id exists already.";
$user = mysql_fetch_array($checkUserId);
print_r($user); // the data returned from the query
}
mysql_close();
如果上面的代码是正确的,那么我需要知道如何使用它
if ($result == $needle) {
echo('found');
} else {
echo('not found');
}