我有一个php文件,它显示了我表中的所有艺术家,并且运行良好。我只是想展示一些有特定条件的艺术家,例如只展示他们所在城市巴尔的摩的艺术家。我不擅长php,希望得到一些帮助。
<?php
$page_title = 'Browse the Prints';
include ('includes/browse_style.html');
require ('../mydesigner/mysqli_connect.php');
// Default query for this page:
$q = "SELECT artists.artist_id, CONCAT_WS(' ', artist_name) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id = prints.artist_id ORDER BY artists.artist_name ASC, prints.print_name ASC";
// Are we looking at a particular artist?
if (isset($_GET['aid']) && filter_var($_GET['aid'], FILTER_VALIDATE_INT, array('min_range' => 1)) ) {
// Overwrite the query:
$q = "SELECT artists.artist_id, CONCAT_WS(' ', artist_name, artist_city, artist_type, artist_mobile) AS artist, print_name, price, description, print_id FROM artists, prints WHERE artists.artist_id=prints.artist_id AND prints.artist_id={$_GET['aid']} ORDER BY prints.print_name";
}
// Create the table head:
echo "<link rel='stylesheet' type='text/css' href='http://www.lectmohd.com/mydesigner/includes/css/table2.css' />";
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<th align="left" width="10%">السعر</b></th>
<th align="right" width="40%">الوصف</th>
<th align="right" width="20%">إسم التصميم</th>
<th align="right" width="20%">المصمم</th>
</tr>';
// Display all the prints, linked to URLs:
$r = mysqli_query ($dbc, $q);
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
// Display each record:
echo "'t<tr>
<td align='"right'">'${$row['price']}</td>
<td align='"right'">{$row['description']}</td>
<td align='"right'"><a href='"view_print.php?pid={$row['print_id']}'">{$row['print_name']}</a></td>
<td align='"right'"><a href='"browse_prints.php?aid={$row['artist_id']}'">{$row['artist']}</a></td>
</tr>'n";
} // End of while loop.
echo '</table>';
mysqli_close($dbc);
include ('includes/footer.html');
?>
只需添加带有城市的条件
WHERE artists.artist_id = prints.artist_id AND artists.artist_city = 'Baltimore'