Jump to content

droplist into function


arjanvr

Recommended Posts

How do i put this into a function

<?PHP
    $result = $conn->query("select id, bedrijfsnaam from klanten");
    
    echo "<html>";
    echo "<body>";
    echo "<select name='id'>";

    while ($row = $result->fetch_assoc()) {

                  unset($id, $name);
                  $id = $row['id'];
                  $name = $row['bedrijfsnaam'];
                  echo '<option value="'.$id.'">'.$name.'</option>';
                
}

    echo "</select>";
    echo "</body>";
    echo "</html>";
?>

to have it replace the bedrijfsnaam current input type here into a dropdown list from mysqli database

<?PHP
<form action="" method="post">
                                <div>
                                        [code]<?php if ($id != '') { ?>
                                                <input type="hidden" name="id" value="<?php echo $id; ?>" />
                                                <p>ID: <?php echo $id; ?></p>
                                        <?php } ?>
                                        
                                        <strong>Bedrijfs(naam):</strong> <input type="text" name="bedrijfsnaam"
                                                value="<?php echo $bedrijfsnaam; ?>"/><br/>
                                        <strong>Factuurbedrag:</strong> <input type="text" name="factuurbedrag"
                                                value="<?php echo $factuurbedrag; ?>"/><br/>
                                        <strong>Vervaldatum:</strong> <input type="text" name="vervaldatum"
                                                value="<?php echo $vervaldatum; ?>"/><br/>
                                        <strong>Voldaan (ja/nee):</strong> <input type="text" name="voldaan"
                                                value="<?php echo $voldaan; ?>"/><br/>
                                        <strong>Opmerkingen:</strong> <input type="text" name="opmerkingen"
                                                value="<?php echo $opmerkingen; ?>"/><p/>
                                        <input type="submit" name="submit" value="Submit" />
                                </div>
                                </form>
?> 
Link to comment
https://forums.phpfreaks.com/topic/282410-droplist-into-function/
Share on other sites

 

How do i put this into a function

 

It's a little ugly, but it could help you what the function is.

function OutputData($sql) {

    $outputs = '';

    $result = $conn->query($sql);   
   
    $outputs .= "<html><body><select name='id'>";

    while ($row = $result->fetch_assoc()) {

                  unset($id, $name);
                  $id = $row['id'];
                  $name = $row['bedrijfsnaam'];
                  $outputs .= '<option value="'.$id.'">'.$name.'</option>';
                
     } 

     $outputs .="</select></body></html>";
     
     return $outputs;
    }

Can you tell me how to replace

 <strong>Bedrijfs(naam):</strong> <input type="text" name="bedrijfsnaam"
                                                value="<?php echo $bedrijfsnaam; ?>"/><br/>

With that function? The list is generated form a different table then the rest of the fields are put in to

<?PHP
<form action="" method="post">
                                <div>
                                        [code]<?php if ($id != '') { ?>
                                                <input type="hidden" name="id" value="<?php echo $id; ?>" />
                                                <p>ID: <?php echo $id; ?></p>
                                        <?php } ?>
                                        
                                        <strong>Bedrijfs(naam):</strong> <input type="text" name="bedrijfsnaam"
                                                value="<?php echo $bedrijfsnaam; ?>"/><br/>
                                        <strong>Factuurbedrag:</strong> <input type="text" name="factuurbedrag"
                                                value="<?php echo $factuurbedrag; ?>"/><br/>
                                        <strong>Vervaldatum:</strong> <input type="text" name="vervaldatum"
                                                value="<?php echo $vervaldatum; ?>"/><br/>
                                        <strong>Voldaan (ja/nee):</strong> <input type="text" name="voldaan"
                                                value="<?php echo $voldaan; ?>"/><br/>
                                        <strong>Opmerkingen:</strong> <input type="text" name="opmerkingen"
                                                value="<?php echo $opmerkingen; ?>"/><p/>
                                        <input type="submit" name="submit" value="Submit" />
                                </div>
                                </form>
?> 

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.