Shenzi1985 Posted December 12, 2011 Share Posted December 12, 2011 ok im back quicker than i thought.... i got my drop box sorted and i got it reloading the page. so it all works correctly. but how do i get the page to display information regarding the film i have selected in the drop box.? i have no code for this at the mo. also i would like the drop box to display the selected item at top of box when it refreshes code for drop box: <FORM> <?php $result = mysql_query( "SELECT * FROM movie_info ORDER BY title ASC ") ; echo "<select name= Film onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_array($result)){ ?> <?php echo "<option value='$nt[id]'>$nt[title] </option>"; } ?> </select> </FORM> any help would be great Quote Link to comment Share on other sites More sharing options...
Andy-H Posted December 12, 2011 Share Posted December 12, 2011 <FORM> <?php $result = mysql_query( "SELECT * FROM movie_info ORDER BY title ASC ") ; echo "<select name='Film' onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_assoc($result)){ if ( $_POST['film'] == $nt['id'] ) { echo '<option value="'. $nt['id'] .'" selected="selected">'. $nt['title'] .'</option>'; }else{ echo '<option value="'. $nt['id'] .'">'. $nt['title'] .'</option>'; } } ?> </select> </FORM> Changed mysql_fetch_array to mysql_fetch_assoc as it selects less data (associative array keys rather than assoc and numerical) and therefor uses less memory. Check if $_POST['field'] is equal to the current movie_info->id and if it is add selected="selected" to the option Quote Link to comment Share on other sites More sharing options...
Shenzi1985 Posted December 12, 2011 Author Share Posted December 12, 2011 thanks. but how do i get it to display for instance a summary of the film, when i select the film from the drop down menu? this is my main problem. Quote Link to comment Share on other sites More sharing options...
Andy-H Posted December 13, 2011 Share Posted December 13, 2011 <?php if ( isset($_POST['field']) ) { $result = mysql_query( "SELECT * FROM movie_info WHERE id = " (int) $_POST['field'] ." LIMIT 1"); $row = mysql_fetch_assoc($result); echo '<pre>'. print_r($row, 1) . '</pre>'; } else { ?> <FORM><?php $result = mysql_query( "SELECT * FROM movie_info ORDER BY title ASC "); echo "<select name='Film' onChange='submit()' >film name</option>"; while ($nt=mysql_fetch_assoc($result)){ if ( $_POST['film'] == $nt['id'] ) { echo '<option value="'. $nt['id'] .'" selected="selected">'. $nt['title'] .'</option>'; }else{ echo '<option value="'. $nt['id'] .'">'. $nt['title'] .'</option>'; } } } ?> </select> </FORM> Quote Link to comment Share on other sites More sharing options...
Shenzi1985 Posted December 13, 2011 Author Share Posted December 13, 2011 $result = mysql_query( "SELECT * FROM movie_info WHERE id = " (int) $_POST['field'] ." LIMIT 1"); it says theres an error on that line. and i cant spot it Quote Link to comment Share on other sites More sharing options...
kney Posted December 13, 2011 Share Posted December 13, 2011 Forgot a dot $result = mysql_query( "SELECT * FROM movie_info WHERE id = " . (int) $_POST['field'] ." LIMIT 1"); Quote Link to comment Share on other sites More sharing options...
Shenzi1985 Posted December 13, 2011 Author Share Posted December 13, 2011 i still dont understand how this helps? i have my drop down box that submits on selection. i now need to load another item from the database depending on the selection of the drop box. e.g i select avatar from the drop list. (it refreshes the page) now the page has the id number of the film in the addressbar as well but i now want it to load the summary of that film. how do i get it to carry the id number over so i can use that to find the data? im totally new to php and js Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.