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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.