Jump to content


Photo

php / sql select list help please


  • Please log in to reply
6 replies to this topic

#1 seandon01

seandon01
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationSan Francisco

Posted 14 June 2006 - 09:10 AM

The objective of this is to create a dynamic select list...
My Current Code:
<?
 $chptrfile_query = mysql_query("SELECT DISTINCT file_name,chapter_id FROM video_file WHERE listing_id=1");
              $myresults = mysql_fetch_assoc($chptrfile_query);
              
              $chptrtitle_query = mysql_query("SELECT DISTINCT chapter_title,id FROM chapters WHERE id=$myresults[chapter_id]");
            $myresults2 = mysql_fetch_assoc($chptrtitle_query);
             echo  $myresults['file_name'];
             echo "<br>";
             echo $myresults2['chapter_title'];
?>

This Returns:

losfelizvillas (which i want to be the value of the select list)
Full Trailer (which i want to be the display name of the select list)


My issue is.. Looping through the results so all the results are in the select list rather then just the first.... I hope this make sense and that someone can guide me to my solution. Thank you so much in advance

#2 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 09:33 AM

try putting $myresults2 into a while loop

eg:
while($myresults2 = mysql_fetch_assoc($chptrtitle_query)){
             echo  $myresults['file_name'];
             echo "<br>";
             echo $myresults2['chapter_title'];
             // your option tags would go here, rather than the echos above
}

If you're not part of the solution, you're part of the precipitate

#3 seandon01

seandon01
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationSan Francisco

Posted 14 June 2006 - 09:39 AM

thanks for the quick reply... unfortunately. that didnt do the trick. Returned the same results as the original code..

#4 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 09:50 AM

Try this. How many results does it say are returned?

<?    $chptrfile_query = mysql_query("SELECT DISTINCT file_name,chapter_id FROM video_file WHERE listing_id=1");
        $myresults = mysql_fetch_assoc($chptrfile_query);
              
        $chptrtitle_query = mysql_query("SELECT DISTINCT chapter_title,id FROM chapters WHERE id=$myresults[chapter_id]");
            $num = mysql_num_rows($chptrtitle_query);
            echo "$num results returned<br><br>";
            while($myresults2 = mysql_fetch_array($chptrtitle_query)){
                echo  $myresults['file_name'];
                 echo "<br>";
                echo $myresults2['chapter_title'];
                echo "<br><br>";
            }    ?>

If you're not part of the solution, you're part of the precipitate

#5 seandon01

seandon01
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationSan Francisco

Posted 14 June 2006 - 09:58 AM

[!--quoteo(post=383696:date=Jun 14 2006, 02:50 AM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Jun 14 2006, 02:50 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Try this. How many results does it say are returned?

<?    $chptrfile_query = mysql_query("SELECT DISTINCT file_name,chapter_id FROM video_file WHERE listing_id=1");
        $myresults = mysql_fetch_assoc($chptrfile_query);
              
        $chptrtitle_query = mysql_query("SELECT DISTINCT chapter_title,id FROM chapters WHERE id=$myresults[chapter_id]");
            $num = mysql_num_rows($chptrtitle_query);
            echo "$num results returned<br><br>";
            while($myresults2 = mysql_fetch_array($chptrtitle_query)){
                echo  $myresults['file_name'];
                 echo "<br>";
                echo $myresults2['chapter_title'];
                echo "<br><br>";
            }    ?>
[/quote]
It says 1 result returned



#6 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 14 June 2006 - 10:06 AM

So are you wanting to loop through the results of the first query as well?

If so, try this:

<?    $chptrfile_query = mysql_query("SELECT DISTINCT file_name,chapter_id FROM video_file WHERE listing_id=1");
        while($myresults = mysql_fetch_assoc($chptrfile_query)){
            $chptrtitle_query = mysql_query("SELECT DISTINCT chapter_title,id FROM chapters WHERE id=$myresults[chapter_id]");
            while($myresults2 = mysql_fetch_array($chptrtitle_query)){
                echo  $myresults['file_name'];
                 echo "<br>";
                echo $myresults2['chapter_title'];
                echo "<br>";
            }
        }    ?>

If you're not part of the solution, you're part of the precipitate

#7 seandon01

seandon01
  • Members
  • PipPip
  • Member
  • 11 posts
  • LocationSan Francisco

Posted 14 June 2006 - 10:10 AM

[!--quoteo(post=383701:date=Jun 14 2006, 03:06 AM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Jun 14 2006, 03:06 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
So are you wanting to loop through the results of the first query as well?

If so, try this:

<?    $chptrfile_query = mysql_query("SELECT DISTINCT file_name,chapter_id FROM video_file WHERE listing_id=1");
        while($myresults = mysql_fetch_assoc($chptrfile_query)){
            $chptrtitle_query = mysql_query("SELECT DISTINCT chapter_title,id FROM chapters WHERE id=$myresults[chapter_id]");
            while($myresults2 = mysql_fetch_array($chptrtitle_query)){
                echo  $myresults['file_name'];
                 echo "<br>";
                echo $myresults2['chapter_title'];
                echo "<br>";
            }
        }    ?>
[/quote]
JACKPOT!!!!!! WOW.. I CANNOT THANK YOU ENOUGH!!!! THANK YOU THANK YOU THANK YOU!!!!
As you can tell i am fairly new with php and sql, didnt even think to my 2nd select statement inside of a loop.. Didnt even know that it was possible actually.. Thanks again...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users