Jump to content

Recommended Posts

The objective of this is to create a dynamic select list...
My Current Code:
[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'];
?> [/code]

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
Link to comment
https://forums.phpfreaks.com/topic/11961-php-sql-select-list-help-please/
Share on other sites

try putting $myresults2 into a while loop

eg:
[code]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
}[/code]
Try this. How many results does it say are returned?

[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]");
            $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>";
            }    ?>[/code]
[!--quoteo(post=383696:date=Jun 14 2006, 02:50 AM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Jun 14 2006, 02:50 AM) [snapback]383696[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Try this. How many results does it say are returned?

[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]");
            $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>";
            }    ?>[/code]
[/quote]
It says 1 result returned

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

If so, try this:

[code]<?    $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>";
            }
        }    ?>[/code]
[!--quoteo(post=383701:date=Jun 14 2006, 03:06 AM:name=sanfly)--][div class=\'quotetop\']QUOTE(sanfly @ Jun 14 2006, 03:06 AM) [snapback]383701[/snapback][/div][div class=\'quotemain\'][!--quotec--]
So are you wanting to loop through the results of the first query as well?

If so, try this:

[code]<?    $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>";
            }
        }    ?>[/code]
[/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...
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.