Jump to content

Archived

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

digitalgod

logic problem?

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.

Share this post


Link to post
Share on other sites
anyone?  I keep trying a lot of different things but I fear that my eyes are too tired and I'm getting lost in my own code

Share this post


Link to post
Share on other sites
Remove line [code]$data=mysql_fetch_array($query);[/code]

Share this post


Link to post
Share on other sites

×

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.