Jump to content

logic problem?


digitalgod

Recommended Posts

hey guys,

what I'm basicly trying to do is populating a table with elements from one table and at the same time selecting the element that's in another table... don't know if that made sense but here's what I mean

[code]
<?php
$result=mysql_query("SELECT * FROM events WHERE name='". $name ."'") or die(query_error());
$row=mysql_fetch_array($result);

$query=mysql_query("SELECT * FROM djs") or die(query_error());
$data=mysql_fetch_array($query);

$aDj = array();
//putting in the array all of the names of the djs in the djs table
while ($data2 = mysql_fetch_array($query)) {
array_push($aDj,$data2['name']);
}
?>

<select name="dj" id="dj">
          <option>Choose one</option>
          <?php
//populating the drop down with that array but selecting the dj that is in the table events
foreach ($aDj as $val) {
    echo "<option value='$val'";
      if ($val==$data['name']) { echo " selected"; }
      echo ">".$val;
      }
?>
        </select>
[/code]

right now I have 2 names but for some reason it's only displaying the one that isn't in the events, can't figure out why.
Link to comment
https://forums.phpfreaks.com/topic/14333-logic-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.