我无法弄清楚如何在此代码中实现连接。还有第二个问题是我想'Charity No: '.$don['charity_id'].'<br/>'.
在 mysql_query中使用("SELECT * FROM charity where id='?????????'")
代码现在所做的是它检索所有这些数据,这很好,但我想要charity_id [FK](在捐赠表中)作为charityname(来自慈善表),并且我确定这是使用连接完成的但是无法弄清楚如何在我的代码中执行此操作。第二个问题是我想创建一个评级系统,对慈善机构进行评级(基于慈善机构编号),数据在上面几行,但我也无法弄清楚。
我的代码是:
<?php
if (!isset($_POST['do']) || !isset($_POST['id']) || !$_POST['id'])
exit;
require_once 'connection.php';
$don=mysql_fetch_assoc(
mysql_query('SELECT *
FROM donation
WHERE id="'.mysql_real_escape_string($_POST['id'],$con).'"',$con));
if ($don===false || !$don['id'])
print '<h3>Donation id #'.$_POST['id'].' does not exist!</h3>';
else {
print '<h3>Information about donation id #'.$_POST['id'].'</h3>'.
'Donor ID: '.$don['donor_id'].'<br/>'.
'Charity No: '.$don['charity_id'].'<br/>'.
'Date & Time: '.$don['TransactionTime'].'<br/>'.
'Donation Amount: £ '.number_format($don['D_Amount'],2).'<br/>'.
}
$find_data = mysql_query("SELECT * FROM charity where id='?????????'");
while($row = mysql_fetch_assoc($find_data))
{
$id = $row['id'];
$C_Name = $row['CharityName'];
$C_Desc = $row['CharityDescription'];
$Hits = $row['Hits'];
$Ranking = $row['Ranking'];
echo "
<form action='rate.php' method='POST'>
$C_Name: <select name='Ranking'>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
<input type='hidden' value=$id name='ID'>
<input type='submit' value='Rate'>;
</form>
";
}
我现在尝试的 JOIN 是:
$don=mysql_fetch_assoc(
mysql_query('SELECT *
FROM donation As D JOIN charity as C ON d.charity_id=C.id
WHERE id="'.mysql_real_escape_string($_POST['id'],$con).'"',$con));
但现在运气。
给予任何帮助将不胜感激,谢谢。