Jump to content

retrieving info


Shenzi1985

Recommended Posts

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 :)

Link to comment
https://forums.phpfreaks.com/topic/253032-retrieving-info/
Share on other sites

<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

Link to comment
https://forums.phpfreaks.com/topic/253032-retrieving-info/#findComment-1297306
Share on other sites

 

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

 

Link to comment
https://forums.phpfreaks.com/topic/253032-retrieving-info/#findComment-1297415
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/253032-retrieving-info/#findComment-1297443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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