Jump to content

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