FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


how to put what you have query in a drop down list?





glena
can someone help me with my problems please.. i would like to put what i have query in a drop down list where it came from when i save it... please help me with this
alalex
Can you explain better what you want to do? Im not sure I understand it...
There are some mysql functions that return some info:
http://dev.mysql.com/doc/refman/5.0/en/query-results.html
In case that was what you wanted..
glena
i have a registration form that uses a drop down list drop down list. i have created an edit form, i have to show first the info's that i register in the database.. my problem is how to show those infos that from the database back to drop down list
alalex
well firstly you would select them:
Code:
 $query = "SELECT * FROM table WHERE whatever = '$something'";

To select with a given condition, if not just put:
Code:
 $query = "SELECT * FROM table ";

Next remember to run the query:
Code:
$result = mysql_query($query);

Now you'll have the results in $result, use them to fetch data and insert it into the select box:
Code:
$total= mysql_numrows($result);
echo '<select name="results">';
for ($i=0; $i<$total; $i++){
echo '<option value="'.$i.'">'.mysql_result($result,$i,'columnName').'</option';
}
echo '</select>';

So now here you have the select and display results code...
I'm not sure this is what you need, but this is what I understood you wanted Sad
glena
for example i have this one:

Code:

<select name = "dropdown">

            <option value="1">1</option>
            <option value="2">2</option>
            <option value="3">3>/<option>
</select>


i selected 3 and save it... and then redirected to login form.. when i login i click the edit.. thats where my problem is the default is 1 and i selected 3 when i register how can i make that?
alalex
Ooh, I think I understand what you mean, so you already have the script to save it:
Now here is how you could do it:
Code:
//php is already opened...
$selected = //put here the result of the query to select what is the default number
function ifSel($value,$selected){
     if($value == $selected){
           echo 'selected="selected"';
     }
}
?>
<select name = "dropdown">
            <option value="1" <?php ifSel('1',$selected); } ?>>1</option>
            <option value="2" <?php ifSel('2',$selected); } ?>>2</option>
            <option value="3" <?php ifSel('3',$selected); } ?>>3>/<option>
</select>

And this way it would automatically select the option with the value that was stored in the db. (You'll have to do the queries before this, and store the actual selection in $selected)
glena
owkie thanks... ill try it... thank you so much for your great help...
Related topics
Windows Tips&tricks!
Drop down menu things
[JS] selecting an option from a drop down box
Allow IPB or Vbulletin
Javascript Drop down menus
Images in avatar gallery
Run Linux from CD
Question About Drop-Down search buttons
drop down menus
Imagine:What you would do if Frihost drop down?
help on a drop down menu!! Please Read!!
Help me about Drop Down List Boxe?
Do you lose PR when using a drop down menu?
"Drop Down List Box" Using PHP and MySql
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.