26. marts 2016 - 08:44
Der er
2 kommentarer
echo HTML modal i while loop
Hejsa Jeg er i gang med at lave en brugerprofilside, hvor man kan ændre sine oplysninger. I min while loop printer jeg de oplysninger fra min MySQL db som man skal kunne redigere i. Udfra hvert felt kan man trykke på 'change', og en modalbox kommer op, hvor man kan ændre den pågældende (informationn. I den modalbox der er i understående kode, er det kun username man kan ændre) Men hvor skal den modal HTML kode ind. Det er vel ikke særlig praktisk at printe den 5 gange i en while loop, så kan man gemme den html kode i en variabel, og så kalde variablen fra min while loop, eller er der en anden smart måde at gøre det på? mvh Madsprofile.php <div class="bs-docs-section"> <h2 id="tables-hover-rows"> Profile Settings </h2> <p> Change your profile settings here. </p> <div class="bs-example"> <table class="table table-hover"> <thead> <tr> <th> # </th> <th> Information </th> <th> </th> <th> <h5 a href="../../php/user/test.php">Change</h5> --> </th> </tr> </thead> <tbody> <?php $stmt = $mysqli->prepare("SELECT firstname, lastname, username, email, password FROM login WHERE username ='$_SESSION[username]'"); $stmt->execute(); $firstname = null; $lastname = null; $username = null; $email = null; $password = null; $stmt->bind_result($firstname, $lastname, $username, $email, $password); while($stmt->fetch()) { echo "<tr><td>Firstname</td><td>".$firstname."</td><td><h5><a href='test.php'>Change</a></h5></td></tr>". "<tr><td>Lastname</td><td>".$lastname."</td><td><h5><a href='test.php'>Change</a></h5></td></tr>". "<tr><td>Username</td><td>".$username."</td><td><h5><a href='test.php'>Change</a></h5></td></tr>". "<tr><td>Email</td><td>".$email."</td><td><h5><a href='test.php'>Change</a></h5></td></tr>". "<tr><td>Password</td><td>".$password."</td><td><h5><a href='test.php'>Change</a></h5></td></tr>"; } $stmt->close(); $mysqli->close(); ?> </tbody> </table> </div> <!-- /example --> </div> <!-- Docs Section end --> </div> <!--container end--> </div> } Modal <div class="container"> <h2>Modal</h2> <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="form-wrapper-change-userinformation"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="form-wrapper-change-userinformation"> <!-- Modal --> <div class="form-wrapper-change-userinformation"> <form class="form-signin wow fadeInUp" method="post" action=""> <h2 class="form-signin-heading">Update</h2> <div class="login-wrap"> <hr> <p>Username</p> <input id="disabledInput" type="text" disabled class="form-control" name="username" placeholder="User ID" value="<?php $stmt = $mysqli->prepare("SELECT username FROM login WHERE username ='$_SESSION[username]'"); $stmt->execute(); $username = null; $stmt->bind_result($username); while($stmt->fetch()) { echo $username; } ?>"> <hr> <input type="text" class="form-control" name="username" placeholder="New Username" autofocus> </hr> </label> <button class="btn btn-lg btn-login btn-block">Update<a href="index.php?todo=logout">Update</a></button> </div> </form> </div> <!-- End Modal Container --> </div> <!-- End Modal Content --> </div> <!-- End Modal Content --> </div> <!-- End Modal-dialog --> </div> <!-- End Container -->
Annonceindlæg fra Computerworld it-jobbank
05. april 2016 - 08:09
#1
Jeg tænker man kunne lave en PHP funktion som hedder Modal og som har 2 værdier med sig. Name og placeholdertext. Så kan du bruge funktionen til hver af dine linjer man skal kunne opdatere. Har rettet den kort til hvordan jeg tror ville lave det. Har ikke testet koden nedenfor. Men håber det giver inspiration. <?php function Modal($Name, $Placeholdertext){ ?> <div class="container"> <h2>Modal</h2> <!-- Trigger the modal with a button --> <button type="button" class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModal">Open Modal</button> <!-- Modal --> <div class="modal fade" id="myModal" role="dialog"> <div class="modal-dialog"> <!-- Modal content--> <div class="form-wrapper-change-userinformation"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal">×</button> <h4 class="modal-title">Modal Header</h4> </div> <div class="form-wrapper-change-userinformation"> <!-- Modal --> <div class="form-wrapper-change-userinformation"> <form class="form-signin wow fadeInUp" method="post" action=""> <div class="login-wrap"> <input type="text" class="form-control" name="<?php print "$Name"; ?>" placeholder="<?php print "$Placeholdertext"; ?>" autofocus> <button class="btn btn-lg btn-login btn-block">Update<a href="index.php?todo=logout">Update</a></button> </div> </form> </div> <!-- End Modal Container --> </div> <!-- End Modal Content --> </div> <!-- End Modal Content --> </div> <!-- End Modal-dialog --> </div> <!-- End Container --> <?php } ?> <div class="bs-docs-section"> <h2 id="tables-hover-rows"> Profile Settings </h2> <p> Change your profile settings here. </p> <div class="bs-example"> <div style="float: left; width: 100%;"> <!-- /Overskrift --> <div style="float: left; width: 150px;"></div> <div style="float: left; width: (350px - 160px);"></div> <div style="float: left; width: (100% - 360px);"></div> <!-- /Data --> <?php $stmt = $mysqli->prepare("SELECT firstname, lastname, username, email, password FROM login WHERE username ='$_SESSION[username]'"); $stmt->execute(); $firstname = null; $lastname = null; $username = null; $email = null; $password = null; $stmt->bind_result($firstname, $lastname, $username, $email, $password); while($stmt->fetch()) { ?> <div style="float: left; width: 150px;">Firstname</div> <div style="float: left; width: (350px - 160px);"><?php print "$firstname"; ?></div> <div style="float: left; width: (100% - 360px);"><a onclick="document.getElementById('UpdateFirstname').style.display = 'block'" href='test.php'>Change</a></div> <div id="UpdateFirstname" style="float: left; width: 100%; display: none;"><?php Modal("Firstname", "New firstname"); ?></div> <div style="float: left; width: 150px;">Lastname</div> <div style="float: left; width: (350px - 160px);"><?php print "$lastname"; ?></div> <div style="float: left; width: (100% - 360px);"><a onclick="document.getElementById('UpdateLastname').style.display = 'block'" href='test.php'>Change</a></div> <div id="UpdateLastname" style="float: left; width: 100%; display: none;"><?php Modal("Lastname", "New lastname"); ?></div> <div style="float: left; width: 150px;">Username</div> <div style="float: left; width: (350px - 160px);"><?php print "$username"; ?></div> <div style="float: left; width: (100% - 360px);"><a onclick="document.getElementById('UpdateUsername').style.display = 'block'" href='test.php'>Change</a></div> <div id="UpdateUsername" style="float: left; width: 100%; display: none;"><?php Modal("Username", "New username"); ?></div> <div style="float: left; width: 150px;">Email</div> <div style="float: left; width: (350px - 160px);"><?php print "$email"; ?></div> <div style="float: left; width: (100% - 360px);"><a onclick="document.getElementById('UpdateEmail').style.display = 'block'" href='test.php'>Change</a></div> <div id="UpdateEmail" style="float: left; width: 100%; display: none;"><?php Modal("Email", "New email"); ?></div> <div style="float: left; width: 150px;">Password</div> <div style="float: left; width: (350px - 160px);"><?php print "$password"; ?></div> <div style="float: left; width: (100% - 360px);"><a onclick="document.getElementById('UpdatePassword').style.display = 'block'" href='test.php'>Change</a></div> <div id="UpdatePassword" style="float: left; width: 100%; display: none;"><?php Modal("Password", "New password"); ?></div> <?php } $stmt->close(); $mysqli->close(); ?> </div> </div> <!-- /example --> </div> <!-- Docs Section end --> </div> <!--container end--> </div>
05. april 2016 - 08:11
#2
manglede lige at skrive calc ved width width: (100% - 360px); width: calc(100% - 360px);
Vi tilbyder markedets bedste kurser inden for webudvikling