0

How can i start it? I know that i need to make an mysql query, but how to transform data, in options in the dropdown list. And remember, it's inside a form, to send the result from a MySQL table.

(EDIT)

I am working inside a printf That is what i want:

<?php ob_start();
include('/../../config.php'); 

if(isset($_POST['edit_id']) && !empty($_POST['edit_id'])) { 

$edit_id = mysql_real_escape_string($_POST['edit_id']); 
$result = mysql_query("SELECT username, password, nome, cidade, pais, base, isactive,   admin, dov, checador, dinheiro, email, datanascimento, profissao, idivao, idvatsim, horas, rank FROM acars_users WHERE `id`='".$edit_id."'");
$resultdl = mysql_query("SELECT * FROM acars_hubs");

$data = mysql_fetch_array($result);
$dl = mysql_fetch_array($resultdl); 


printf("<div  align=\"center\">
<br><form method=\"post\" action=\"editar2.php\">
<p><font size=\"2\" face=\"Segoe UI, Arial, Helvetica, sans-serif\"   align=\"center\">Modifique os campos que deseja para <strong>editar este membro.</font><br>
<br>

<table width=\"700\" border=\"0\" align=\"center\" >
<tr>
    <td>Base Operacional:</td>
    <td><label for=\"hub\"></label>
      <select name=\"hub\">
         <option>".$dl['name']."</option>
       </select>
    </td>
    </td>
</tr>
</table></br></br>
<input name=\"edit_id\" value=\"$edit_id\" type=\"hidden\">
<input type=\"image\" src=\"img/Editar.PNG\" width='85' height='30'></form>
</form>

</table> 
</div>

");
while ($data = mysql_fetch_array($result));
while ($dl = mysql_fetch_array($resultdl));
ob_end_flush();
?>

2 Answers 2

2

Do you mean something like this?

<select>
<?php while($row = mysql_query("SELECT * FROM table")){ ?>
<option><?=$row['column']; ?></option>
<?php } ?>
</select>
Sign up to request clarification or add additional context in comments.

3 Comments

I actually have 3, but only 2 results appear. The first one is always hidden. That is what i did: code ....<td class=\"tabeladados\">Base Operacional:</td> <td class=\"tabeladados\"><label for=\"hub\"></label> <select name=\"hub\"> "); while ($dl = mysql_fetch_array($resultdl)){ echo "<option value=" . $dl['name'] . ">" . $dl['name'] . "</option>"; } printf(" </select> </td>....
What does $resultd1 equal?
Its resultdL, not d1, its dL from DropList. code $dl = mysql_fetch_array($resultdl); and code $resultdl = mysql_query("SELECT * FROM acars_hubs");
0

I've discovered the problem. My first $dl = mysql_fetch_array($resultdl, MYSQL_ASSOC); pulls the first row from the table. When I start while loop the mysql_fetch_array picks up with the next row. So, the solution is remove the first call. This is the final code:

<?php 
   include('../../../../../config.php'); 

    if(isset($_POST['edit_id']) && !empty($_POST['edit_id'])) {

    $edit_id = mysql_real_escape_string($_POST['edit_id']); 

    $result = mysql_query("SELECT * FROM acars_users WHERE `id`='".$edit_id."'");
    $data = mysql_fetch_array($result);
    $resultdl = mysql_query("SELECT * FROM acars_hubs");

    printf("<div  align=\"center\">
    <form method=\"post\" action=\"actions/actions_editar.php\">
    ");

           while ($dl = mysql_fetch_array($resultdl, MYSQL_ASSOC)){

        printf(" 
        <option value=".$dl["id"].">".$dl["name"]."</option>;
        ");

           }

    printf("
        <input name=\"edit_id\" value=\"$edit_id\" type=\"hidden\">
        <input type=\"image\" src=\"../../images/botao_editar.PNG\" width='85' height='30'></form>
        ");

?>

2 Comments

Thanks for this! I think this will help me. I think you should change the question, if you can, to reflect what the real problem is. I.e., "Fetch array results for a dropdown form list". I read this by chance out of curiosity, but may have found the answer to a problem I was having with a while loop.
Never mind; I edited the question. (PHPMyAdmin is not relevant to the question.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.