mysql - how to show fixed images on pageload in php?
I have a php page where user can select one category via dropdown list and after clicking 'go' button the relative images for that category will display on page below the dropdown list from database. This works fine. Now I want to display the images on page load for the 1st dropdown list category everytime then after based on user choice. I think my point is clear to all. for example, 1st category in the dropdown is Featured art, on loading the php page images related to Featured art always display on page. After that user can change it by changing the category from dropdown. Help me please. Here is my complete code :
<body>
<?php
include ('connect-db.php');
?>
<form name="product" method="post" action="">
<table align="right" width="10%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>Category</td>
<td>
<select name="category">
<?php
$sql = "SELECT id, art_name FROM category;";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
?>
<option value="<?= $row['id']; ?>"><?= $row['art_name']; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input name="go" type="submit" value="Go" /></td>
</tr>
</table>
</form>
<div align="center">
<ul >
<?php
$id = (int)$_POST['category'];
$sql_search = "SELECT id, categoryid, path FROM list WHERE categoryid = $id";
$search = mysql_query($sql_search);
if (isset($_POST['go'])) {
while ($row = mysql_fetch_assoc($search)) {
?>
<li><a href="<?= $row['path']; ?>" onclick="return hs.expand(this)"><img src="<?= $row['path']; ?>" border="0"></a></li>
<?php }
}
else {
}
?>
</ul>
</div>
</body>
Thanks in advance!:)
Answer
Solution:
You may try to use
GET
request instead ofPOST
. Using this you may check like:Also, in the dropdown, set the default / first category selected.
When the user selects another option, redirect to url?category=<selected-id>
Hope this helps!
Vivek