1

投稿を調べて Google を使用した後、答えの基本的なコンポーネントがあると思いますが、MySQL の経験がないため、それらをまとめる方法が完全にはわかりません。

---編集開始 (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'); 
}
4

1 に答える 1

0

あなたのコードはすでに $needle が見つかるかどうかをテストしています

if (mysql_num_rows($checkUserId) > 0) {

この小さな行は、クエリに一致する結果の数を探します。0 を超える場合 (つまり、一致が見つかった場合)、続行します。

リクエストに一致するには:

if (mysql_num_rows($checkUserId) > 0) 
  {
  echo "found";
  {
else
  {
  echo "not found";
  }
于 2013-10-16T09:31:44.407 に答える