php - How to display images from mysql table after selection of a dropdown category from database? -
i want show category based shopping items images on web page can found in online shopping sites.i crated two mysql tables: ist id, category_name , 2nd id, categoryid, product, image_path. able display product images @ time on page, don't know how show product images of single category selected dropdown list submit button @ top of page. hope point clear otherwise feel free ask me.
below attached code shows product images on php page @ time without dropdown list. ideas , advice on doing welcome.
<head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <title>untitled document</title> <style type="text/css"> ul, li { list-style-type:none; } ul.display { width: 500px; } ul.display li { float: left; width: 100px; height: 120px; margin-left: 5px; margin-right: 5px; margin-bottom: 5px; position: relative; vertical-align:middle; text-align:center; } ul.display li img { width: 94px; height: 114px; display: inline; } </style> </head> <body> <div align="center"> <?php include('connect.php'); $sql = "select * becuart"; $result = mysql_query( $sql ); echo "<ul class='display'>"; while( $row = mysql_fetch_array( $result ) ) { $filepath = $row["path"]; echo "<li>"; echo "<a href=\"$filepath\"><img src=\"$filepath\" border=\"0\"></a>"; echo "</li>"; } echo "</ul>"; ?> </div> </body> </html>`
because it's way long -> new answer:
<?php include 'dbconnect.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, path 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 class='display'> <?php $id = (int)$_post['category']; $sql_search = "select id, art_name, path category id = $id"; $search = mysql_query($sql_search); if (isset($_post['go'])) { while ($row = mysql_fetch_assoc($search)) { ?> <li><a href="<?= $row['path']; ?>"><img src="<?= $row['path']; ?>" border="0"></a></li> <?php } } else { } ?> </div>
Comments
Post a Comment