我是 PHP 新手,见过一些类似的查询,但我的涉及 2 个数组,我不知道如何将它们放在一起。有人可以帮忙吗?非常感谢!我搬出去做一个网站来卖我的东西,我在表格上有一个选择项目和报价金额部分。我希望它们在电子邮件中彼此相邻出现。
你可以在这里看到我正在制作的网站:http: //www.stasale.com
我有以下代码:
<table border="1">
<tr>
<th>Image</th>
<th>Name</th>
<th>Condition</th>
<th>Description</th>
<th>Asking Price</th>
<th>Select Item</th>
<th>Offer Value</th>
</tr>
<?php
require_once('appvars.php');
require_once('connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "SELECT * FROM stasale ORDER BY date DESC";
$data = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($data)) {
if (is_file(GW_UPLOADPATH . $row['image']) && filesize(GW_UPLOADPATH . $row['image']) > 0) {
echo '<tr><td><img src="' . GW_UPLOADPATH . $row['image'] . '" alt="' . $row['image'] . '" width="100" height="100"/></td>
<td>' . $row['name'] . '</td>
<td>' . $row['condition'] . '</td>
<td>' . $row['description'] . '</td>
<td>' . $row['askingprice'] . '</td>
<td><form method="post" action="mail.php"><input type="checkbox" name="itemname[]" value="' . $row['id'] . '">Select</td>
<td>Offer: <input type="text" name="offer[]"></td></tr>';
}
else {
echo 'Invalid row';
}
} ?>
<tr><td colspan="3">Contact Name:</td><td colspan="4"><input type="text" name="coname" width="300" ></td></tr>
<tr><td colspan="3">Contact Number:</td><td colspan="4"><input type="text" name="conumber" width="300" ></td></tr>
<tr><td colspan="3">Contact Email:</td><td colspan="4"><input type="text" name="coemail" width="300" ></td></tr>
<tr><td colspan="3">Questions/Comments:</td><td colspan="4"><input type="text" name="comments" width="300" height="100"></td></tr>
<tr><td colspan="7" align="center"><input type="submit" value="Send Request" name="submit" style="width:500px"/></form></td></tr>
</table>
我似乎无法弄清楚如何从 itemname[] 或 offer[] 获取值以显示在我的 mail.php 页面中,我觉得这是完全错误的:
if (isset($_POST['submit'])) {
$name = $_POST['coname'];
$email = $_POST['coemail'];
$number = $_POST['conumber'];
$comments = $_POST['comments'];
foreach ($_POST['itemname'] as $itemname)
foreach ($_POST['offer'] as $offer)
{
}
$to = 'shinobuden@gmail.com';
$subject = 'STASALE order';
$msg = "$name, $email, $number, $comments \n" .
"I would like: $itemname" .
"$offer";
mail($to, $subject, $msg, 'From:' . $email);
$to = "$email";
$subject = 'I have received your request - Si';
$msg = 'Thank you for contacting me! I have received your request and will reply shortly! ~ Si x';
$from = 'shinobuden@gmail.com';
mail($to, $subject, $msg, 'From:' . $from);
echo '<p><strong>Thanks for your request. I will respond as soon as possible.</strong></p>';
}
?>
提前谢谢你的帮助!