Search the Community
Showing results for tags 'displaytext'.
-
I am trying to use a <select> <option> to display text on a web page. The data comes from a database. This is what I am attempting: When an option is selected and submit button clicked them some text will be displayed. At the moment I do have text on the web page, but none of the selected options change this. I have four pieces of text: Page 1, Page 2 etc. At the moment Page 4 text is displayed. I would like each piece of text to be displayed. This is the php: <?php // Connect to the database $pdo = new PDO("mysql:host=localhost;dbname=###", "###", ""); $sql = "SELECT * FROM testdb ORDER BY id"; try { $stmt = $pdo->prepare($sql); $stmt->execute(); $data = $stmt->fetchAll(); } catch(Exception $ex){ echo ($ex -> getMessage()); } ?> This is the html: <form name="###" method="post" action="#"> <p></p> <select onchange="reload(this.form)"> <option>test one</option> <?php foreach ($data as $output) { ?> <option value=''><?php echo $output['header']; ?></option> <?php } ?> </select> <br> <button type="submit" value="submit">Submit</button> </form> <?php echo $output['pages']; ?> I would appreciate help with this. However, from previous attempts at adding data to a page I used isset() and I think $_POST(), possibly together. If these are the things I need to use, then please could you include their usage within any examples you feel would help. Thank you.
-
After several attempts, I now have data displayed on my index.php page, but the data is from all rows. Luckily I have two rows. The page also has a menu - with two links. What I would like help with is: How to display index.php with just the data for it - i.e. home page data. How to display data if either the ‘home’ or ‘copyright’ links are clicked. I understand you can use $_GET[‘id’], and isset(), but I don’t know how to do that. I include the full html page code: <?php // database connection require_once('admin/databasecon.php'); ?> <!DOCTYPE html> <html> <?php include 'includes/headsection.php'; ?> <body> <?php // displaying data $table = "pages"; // table $sqli = "SELECT * FROM $table ORDER BY id ASC"; $result = $conn->query($sqli); ?> <!-- topMenu --> <table id="topMenu"> <tr> <td><h1 class="siteName">Scarab Beetle</h1></td> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<td class='navItem'>" . "<a href=index.php>" . $row["menuheader"] . "</a>" . "</td>"; } } ?> </tr> </table> <!-- topMenu end --> <!-- timeline menu --> Menu goes here <!-- timeline menu end --> <!-- page title --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo "<h1 class='centered'>" . $row["pageheader"] . "</h1>"; } } ?> <hr> <!-- page content --> <?php if ($result = mysqli_query($conn, $sqli)) { while($row = $result->fetch_assoc()) { echo $row["pagetext"]; } } ?> <hr> <div class="clear"></div> <!-- footer content --> <?php include 'includes/footersection.php'; ?> <!-- footer content end --> </body> </html> Any help to achieve what I want will be appreciated. Thank you.