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
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
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
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
Share on other sites

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.