Web サイトの検索システムを作成しており、mysql データベースから取得したデータを使用して多数の結果を表示したいと考えています。これは少し問題を引き起こしたので、Web を調べてみると、実際にはmysql_fetch_arrayまたはmysql_fetch_assocを使用して結果を表示できることがわかりました。ただし、検索フォームとアクション ページを実行すると、localhost サーバーがフリーズし、コンピューター (ラップトップ) が過熱し始めます。
どうすればこれを解決できますか?
ところで、while ($user = $mysql->tableCheckArray(_parameters_))
(いくつかのチュートリアルで見つけたように)使用しようとしましたが、上記と同じことが起こりました。
これが私の検索コードです:
if (isset($_POST[search]) && !empty($_POST[search])){
$search = $_POST[search];
$mysql = new mysqlHandle;
$mysql->accessOpen('root', '', 'Portfolio', 'localhost');
// Sets $rows to number of entries with the 'Name' value of $search.
$rows = $mysql->tableCheck('*', stats, Name, $search, Portfolio);
echo '<div id="content">
<div id="content_main">
<h2>Search Results </h2>
<br/><hr/><br/>';
if ($rows>0){
// Sets the row's 'id' / entry number.
$num = 1;
while ($num<$rows){
$user = $mysql->tableCheckArray('*', stats, Name, $search, Portfolio);
echo $user[Name]."<br/>";
echo $user[Image]."<br/>";
echo $user[Age]."<br/>"."<br/>"."<br/>"."<hr/>"."<br/>";
$num++;
}
/*
while ($num<=$rows){
$user = $mysql->tableCheckAssoc('*', stats, Name, $search, Portfolio);
echo $user[Name][$num]."<br/>";
echo $user[Image][$num]."<br/>";
echo $user[Age][$num]."<br/>"."<br/>"."<hr/>"."<br/>";
$num++
}
*/
}else{
echo "No users found";
}
echo '</div>
</div>';
}
これが私のMySQLコードです:
function tableCheckAssoc($span, $table, $column, $value, $base){
$this->span=$span;
$this->table=$table;
$this->column=$column;
$this->value=$value;
$this->database=$base;
mysql_select_db($this->database);
$this->query10="SELECT $this->span FROM $this->table WHERE $this->column = '$this->value'";
$this->result10=mysql_query($this->query10) or die("<br/>"."Invalid $table CHECK query: " .mysql_error());
return mysql_fetch_assoc($this->result10);
}
// Returns array.
function tableCheckArray($span, $table, $column, $value, $base){
$this->span=$span;
$this->table=$table;
$this->column=$column;
$this->value=$value;
$this->database=$base;
mysql_select_db($this->database);
$this->query4="SELECT $this->span FROM $this->table WHERE $this->column = '$this->value'";
$this->result4=mysql_query($this->query4) or die("<br/>"."Invalid $table CHECK query: " .mysql_error());
return mysql_fetch_array($this->result4);
}
// Returns number of rows.
function tableCheck($span, $table, $column, $value, $base){
//accessOpen();
$this->span=$span;
$this->table=$table;
$this->column=$column;
$this->value=$value;
$this->database=$base;
mysql_select_db($this->database);
$this->query="SELECT $this->span FROM $this->table WHERE $this->column = '$this->value'";
$this->result=mysql_query($this->query) or die("Invalid $table CHECK query: " .mysql_error());
return mysql_num_rows($this->result);
}
最初に照会された行の「名前」、「画像」、および「年齢」の値を表示し、次に 3 番目などを表示したいと思います。