php - List data from many to many table -
i'm trying list data "date" table sorted category , i'm stuck. more helpful. how can "select date" list url?
sql structure:
category -cat_id (int)=>pk -name date -id (int)=>pk -url video_cat -id (int) => fk date.id -cat_id (int) => fk category.cat_id
php:
<?php $sql = "select * category"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { if (!empty($_post['category']) , $_post['category'] == $row["cat_id"]) $select = "selected='selected'"; else $select = ''; echo '<option value="' . $row["cat_id"] . '" ' . $select . ' >' . $row["name"] . '</option>'; } } ?> <?php if (!empty($_post['category'])) { $category_id = $_post['category']; $sql = "select * video_cat cat_id = '" . $category_id . "'"; $result = mysql_query($sql); if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { echo '<option value="' . $row["id"] . '">' . $row["url"] . '</option>'; } } } ?>
the answer should this
<?php $sql = "select * category date=$date"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { if(!empty($_post['category']) , $_post['category']==$row["cat_id"]) $select="selected='selected'"; else $select = ''; echo '<option value="'.$row["cat_id"].'" '.$select.' >'.$row["name"].'</option>'; } } ?> <?php if(!empty($_post['category'])) { $category_id = $_post['category']; $sql = "select * video_cat cat_id = '".$category_id."'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { echo '<option value="'.$row["id"].'">'.$row["url"].'</option>'; } } } ?>
Comments
Post a Comment