I'm looking for some help with Select dropdownboxes.
I wrote some code to fill 2 Selectboxes with data from a mysql database with 2 different tables.
The problem is the first rows of both tables don't show in de Selectboxes. I used the while($row =mysqli_fetch_assoc($result)) function but without effect.
The code with the problem is beneath::
I hope somepne can help me out.
// The PHP code below is in a html blok on the page.
// The connection and de select operation works fine.
// a print_r($result) shows that all the rows are in the $result array.
// below the code for opening de database and do 2 selections from different tables.
$servername=......
$username=....
etc. etc.
$conn = new mysqli($servername, $username, $password, $dbname);
// Controleren of de verbinding werkt/ check the connection
if ($conn->connect_error) {
die("Verbinding mislukt: " . $conn->connect_error);
}
// Voer de SQL-query uit
$sql1 = "SELECT w_code,w_naam FROM agc_wandel";
$result1 = $conn->query($sql1);
// Voer de SQL-query uit
$sql = "SELECT * FROM naw_gidsen";
$result = $conn->query($sql);
$conn->close();
?><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Page</title>
<meta name="generator" content="WYSIWYG Web Builder 19 - https://www.wysiwygwebbuilder.com">
<div id="wb_Form1" style="position:absolute;left:218px;top:488px;width:670px;height:405px;z-index:12;">
<form name="Form1" method="post" action="" enctype="multipart/form-data" target="_self" id="Form1">
// the php code below is in de html from de Select1 object.
// It works but doesn't show the first row of the table.
// What am I doing wrong???
<select name="Select1" size="1" id="Select1" style="position:absolute;left:46px;top:53px;width:257px;height:26px;z-index:0;" autocomplete="off"
<?php
// Controleer of er resultaten zijn> check for results
if (!empty($result)) {
// Output the row data
while($row =mysqli_fetch_assoc($result)) {
echo "<option value='" . $row["voornaam"]. "'>" .$row["voornaam"] . " ". $row["achternaam"]." =>". $row["g_code"]." =>".$row["actie_code"]."</option>";
}
} else {
echo "0 resultaten";
}
?>
=""> // where it comes from????
</select>
// the php code below is in de html from de Select3 object.
// It works but doesn't show the first row of the table.
// What am I doing wrong???
<select name="Select3" size="1" id="Select3" style="position:absolute;left:46px;top:112px;width:257px;height:26px;z-index:1;" autocomplete="off"
<?php
// check for results
if ($result1->num_rows > 0) {
// Output the row data
while($row = mysqli_fetch_assoc($result1)) {
echo "<option value='" . $row["w_code"]. "'>" . $row["w_code"] ." => ". $row["w_naam"]."</option>";
//echo "<option value='" . $row["w_code"]. "'>" . $row["w_code"] ." => ". $row["w_naam"]."</option>";
}
} else {
echo "0 resultaten";
}
?>> //Where is the second hook coming from???
</select>
php problem with select dropdown and mysql tables
Forum rules
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
PLEASE READ THE FORUM RULES BEFORE YOU POST:
viewtopic.php?f=12&t=1901
MUST READ:
http://www.wysiwygwebbuilder.com/forms.html
http://www.wysiwygwebbuilder.com/form_wizard.html
Frequently Asked Questions about Forms
Re: php problem with select dropdown and mysql tables
I cannot help you with programming related questions, but it does not look like this code is correct.
You have placed it inside the <select> tag, so it will break the structure of the HTML.
If you really want to do this then you will have to close the <select> tag first.
For example:
In this case, you will need to remove the '>' from '?>'
You have placed it inside the <select> tag, so it will break the structure of the HTML.
If you really want to do this then you will have to close the <select> tag first.
For example:
Code: Select all
><?php
// your code
?