2016-11-06 3 views
1

Ich versuche, Daten von "Datum" Tabelle nach Kategorie sortiert und ich bin fest. Jede Hilfe wird mehr als hilfreich sein. Wie kann ich das "aus Datum auswählen" auswählen, um die URL aufzulisten?Listet Daten von vielen zu vielen Tabelle

Sql Struktur:

category 
-cat_id (int)=>PK 
-name 

date 
-id (int)=>PK 
-url 

video_cat 
-id (int) => FK to date.id 
-cat_id (int) => FK to category.cat_id 

PHP:

<?php 
$sql = "select * from category"; 
$result = mysql_query($sql); 

if (mysql_num_rows($result) > 0) { 

    while ($row = mysql_fetch_assoc($result)) { 

     if (!empty($_POST['category']) AND $_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 * from video_cat WHERE 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>'; 
     } 
    } 
} 
?> 
+0

ich nicht das Problem klar bekommen. Können Sie mit einem Beispiel mehr über Ihr Problem erfahren? –

+0

Ich versuche, Daten von vielen bis zu vielen Tabellen aufzulisten, aufgelistet nach Kategorie. Mit diesem Code kann ich die Kategorie auswählen, aber die Daten werden nicht von mysql aufgelistet. –

Antwort

0

Die Antwort wie diese

sein sollte
<?php 
$sql = "select * from category WHERE date=$date"; 
$result = mysql_query($sql); 
if(mysql_num_rows($result) > 0) 
{ 
while ($row = mysql_fetch_assoc($result)) { 
if(!empty($_POST['category']) AND $_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 * from video_cat WHERE 
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>'; 
    } 
} 
} 
?> 
Verwandte Themen