Jump to content


Photo

logic problem?


  • Please log in to reply
2 replies to this topic

#1 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 11 July 2006 - 10:23 PM

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

<?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>

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.

#2 digitalgod

digitalgod
  • Members
  • PipPipPip
  • Advanced Member
  • 374 posts

Posted 12 July 2006 - 12:37 AM

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

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 12 July 2006 - 04:47 PM

Remove line
$data=mysql_fetch_array($query);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users