arjanvr Posted September 24, 2013 Share Posted September 24, 2013 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 More sharing options...
jazzman1 Posted September 24, 2013 Share Posted September 24, 2013 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; } Link to comment https://forums.phpfreaks.com/topic/282410-droplist-into-function/#findComment-1451046 Share on other sites More sharing options...
arjanvr Posted September 24, 2013 Author Share Posted September 24, 2013 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> ?> Link to comment https://forums.phpfreaks.com/topic/282410-droplist-into-function/#findComment-1451056 Share on other sites More sharing options...
cyberRobot Posted September 24, 2013 Share Posted September 24, 2013 Have you looked into how functions work? http://www.php.net/manual/en/functions.user-defined.php Link to comment https://forums.phpfreaks.com/topic/282410-droplist-into-function/#findComment-1451063 Share on other sites More sharing options...
arjanvr Posted September 24, 2013 Author Share Posted September 24, 2013 I did but i dont understand it.. yet Link to comment https://forums.phpfreaks.com/topic/282410-droplist-into-function/#findComment-1451087 Share on other sites More sharing options...
Ch0cu3r Posted September 24, 2013 Share Posted September 24, 2013 What have you tried so far? Link to comment https://forums.phpfreaks.com/topic/282410-droplist-into-function/#findComment-1451090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.