0

MySQL データベースに接続してテーブル (builditblocks) をチェックし、ユーザーが「名前」列に指定したデータがあるかどうかを確認しようとしています。

これが私がこれまでに持っているものです:

<?php
 $temp=mysqli_query($con, "SELECT * FROM `builditblocks`.`module_index`.`name`");
 $i = 0;
 while($module = mysqli_fetch_array($temp))
 {
   "moduleArray[".$i."]=\"" . $module["name"]."\";" ;
   $i++
   //stuck here I need to know how to
   //store them all in an array and check
   //to see if the input matches any array elements
 }

テーブルに名前があるかどうかを確認するにはどうすればよいですか?

4

4 に答える 4

1

「WHERE」句と「LIKE」を組み合わせてみてください。

$temp = mysqli_query($con, "SELECT * FROM `builditblocks`.`module_index`.`name` WHERE `name` LIKE '%input%'");

上記のコードは、名前に「input」を含むレコードのみを提供します。詳細については、 http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_likeを参照してください。

于 2013-08-21T14:02:43.703 に答える
0

次のことを試してください。

$name = $module["name"]; // Assign your user input to a variable
$temp = mysqli_query($con, "SELECT * FROM builditblocks.module_index WHERE name = '" . $name . "'"; // Get all fields from table where the name field equals the user input.
if ($temp) {
    // If any records were returned the name exists
} else {
    // Otherwise the name doesn't exist
}

お役に立てれば。

于 2013-08-21T14:15:06.473 に答える