私はおそらく20時間の研究と試行錯誤のためにこれに取り組んできましたが、解決策が見えません.
これがセットアップです。HTML フォームを持つページ (customer_search.php) があります。ユーザーが $last_name で DB を検索し、結果を同じページのテーブルに表示できるようにしたいと考えています。
最初:これは可能ですか?私は過去数日間、非常に多くのことを読んできました。私は自分自身を疑っていますが、Java を使用せずに、純粋に PHP/HTML を使用して実行できると思います。
私もMVCモデルを使用しています。
これはメインページです (customer_search.php)
<?php include '../view/header.php';
?>
<div id="main">
<h1>Customer Search</h1>
<div id="content">
<form action="" method="post" id="aligned"
<label>  Last Name</label>
<input type="text" name="last_name"/>
<br />
<label> <label>
<input type="submit" value="Search" />
</div>
<div id="content">
<h2>Results</h2>
<table>
<tr>
<th>Name</th>
<th>Email Address</th>
<th>City</th>
<th> </th>
</tr>
<tr>
<td><?php echo $_POST['firstName'] .' '. $_POST['last_name']; ?></td>
<td><?php echo $_POST['email']; ?></td>
<td><?php echo $_POST['city']; ?></td>
<td><form action="customer_display.php" method="post">
<input type="hidden" name="action" value="get_customer" />
<input type="hidden" name="customer_id"
value="<?php echo $_POST['customer_ID']; ?>" />
<input type="submit" value="Select" />
</form>
</td>
</tr>
</table>
<br />
</div>
</div>
<?php include '../view/footer.php'; ?>
これは、使用したい関数 get_customers_by_last_name($last_name) を含む MODEL フォルダー内の customer_db.php です。
<?php
function get_customers() {
global $db;
$query = 'SELECT * FROM customers
ORDER BY lastName';
$customers = $db->query($query);
return $customers;
}
function get_customers_by_last_name($last_name) {
global $db;
$query = "SELECT * FROM customers
WHERE lastName = '$last_name'
ORDER BY lastName";
$customers = $db->query($query);
return $customers;
}
コードのオーバーロードをお詫びしますが、これは私の最初の投稿であり、考えられることはすべて試しました。HTMLフォームの姓でDBを検索し、結果をテーブル(同じページ)に表示したいだけで、ページを更新する必要があるかどうかは気にしません。PHP はクライアント側ではなくサーバー側であることを知っているので、更新する必要があります。結果を実際にテーブルに表示することができないようです。結果を取得できた場合、次のステップは顧客を選択して次のページ customer_display.php に渡すことですが、それを超えますそこにブリッジ。ご協力いただきありがとうございます。これに関するヘルプ/レッスンを本当にお願いしています。私は絶望的です!!!!:(