I have the following code:
<form name="votos" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php $categorias=mysql_query("SELECT * FROM categoria") or die (mysql_error()); ?>
<?php while($cat=mysql_fetch_array($categorias)){
echo "<h5>".$cat[0]." - ".$cat[1]."</h5>";
$nomeados=mysql_query("SELECT * FROM nomeados WHERE cod_categoria='$cat[0]'") or die(mysql_error());
?>
<div class="styled-select">
<select name="voto">
<option value=""></option>
<?php
while($nom=mysql_fetch_array($nomeados)){
$nomes=mysql_fetch_array(mysql_query("SELECT nome FROM logins WHERE cod_login='$nom[0]'")) or die (mysql_error());
?>
<option value="<?php echo $nom[0]; ?>"><?php echo $nomes[0]; ?></option>
<?php
}
?></select></div>
<?php }
?>
<input type="submit" class="botao" value="" name="submit" />
</form>
The code shows all the categories with the nomenies in a select box.
The thing is that the select box goes to post with the same name. I don't know how to get the information from all of the select boxes.
If you have more elements with the same name you can post them as an array
<select name="voto[]">
and than you get it in php
$votos = $_POST['voto']
foreach($votos as $voto){
//do what you need to do
}
and it's an array with all the values
Related
I tried putting the loop inside but then when I pick a category it won't print in the echo and if the loop is outside like right now each category is printed alone I want them all in one tab and one go button
<?php
while($row = mysqli_fetch_array($result)) {
$category = $row["category"];
?>
<form action="" method="post">
<select name="work_place">
<option value="<?php echo $category;?>"><?php echo $category;?></option>
</select>
<input type="submit" value="go" />
</form>
<?php
}
<?php
$post = (isset($_POST['work_place'])) ? $_POST['work_place'] : '';
echo $post;
?>
Image of current issue:
<form action="" method="post">
<select name="work_place">
<?php
while($row = mysqli_fetch_array($result)) {
$category = $row["category"];
?>
<option value="<?php echo $category;?>"><?php echo $category;?>
</option>
<?php
} ?>
</select>
<input type="submit" value="go" />
</form>
You want to loop over 'option', only.
You do not want multiple forms and 'select' inputs.
I want the dropdown to show the "client_code", "name" in one line. It almost works but not 100%. I am a beginner with php and SQL, can someone help me please?
Code that doesn't work
<form id="thirdForm" name="form1" action="" method="post">
<select id="klantWidth">
<?php
$queryKlant = "SELECT naam FROM klant";
$queryKlantCode = "SELECT klant_code FROM klant";
$resultKlant=mysqli_query($mysqli,$queryKlant);
$resultKlantCode=mysqli_query($mysqli,$queryKlantCode);
while($row=mysqli_fetch_array($resultKlant) &&
$row2=mysqli_fetch_array($resultKlantCode) )
{
?>
<option><?php echo $row[0]. ", ". $row2[0];?></option>
<?php
}
?>
</select>
</form>
Code that only works with retrieving name in dropdown from database
<form id="thirdForm" name="form1" action="" method="post">
<select id="klantWidth">
<?php
$queryKlant = "SELECT naam FROM klant";
$res=mysqli_query($mysqli,$queryKlant);
while($row=mysqli_fetch_array($res))
{
?>
<option><?php echo $row[0]; ?></option>
<?php
}
?>
</select>
</form>
You can select more than one column from a table in the same select, and as both these columns live in the same table it makes producing this result much simpler.
<form id="thirdForm" name="form1" action="" method="post">
<select id="klantWidth">
<?php
$sql = "SELECT naam, klant_code FROM klant";
$result = mysqli_query($mysqli,$sql);
while($row=mysqli_fetch_array($result)){
?>
<option><?php echo $row[0]. ", ". $row[1];?></option>
<?php
}
?>
</select>
</form>
You probably want to do this with your <option> tag as well rather than put the name and code in the visible portion
<option value="<?php echo $row[1];?>"><?php echo $row[0];?> </option>
And if you use mysqli_fetch_assoc() you can use the columns names so you know what you are putting where
while($row=mysqli_fetch_assoc($result){
<option value="<?php echo $row['klant_code'];?>"><?php echo $row['naam'];?> </option>
The idea is the page in which you select a category from drop-down menu, then after you click remove button, new form shows(contains yes/no buttons) that asks you if you really want to remove selected category. Problem is the second yes/no script. It works on separate page, but on page with first form it doesn't echo anything nor does it remove a pet. Please help, thanks!
<?php
/*remove a category*/
include("connection.php");
?>
<html><head></head>
<body>
<?php
$PetListquery= "SELECT distinct petType From petType ORDER by petType";
$PetListResult= mysqli_query($cxn,$PetListquery) or die ("Couldn't execute query.");
?>
<div style="border:2px solid;">
<form method="POST" action="removeCategory.php">
<div align='left'>
Choose category you want to remove:
<select name='petType'>
<option value='-1'>Type:</option>
<?php
while($row = mysqli_fetch_assoc($PetListResult))
{
extract($row);
?>
<option value='<?php echo $petType;?>' ><?php echo $petType;?> </option>
<?php }?>
</select>
</div>
<div>
<p><input type='submit' name='Remove' value='Remove Category' />
</div>
</div>
</form>
<?php
foreach($_POST as $field => $value)
{ //second form starts after if
if($field == 'petType')
{
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']?>">
<div>
<input name="Yes" type="submit" value="Yes">
<input name="No" type="submit" value="No">
</div>
</form>
<?php
echo "Are you sure you want to delete selected category?";
//clicking any of these buttons doesn't display anything
if(isset($_POST['Yes']))
{
echo "yes";
$DeleteQuery= "DELETE From petType WHERE petType='$petType'";
$DeleteResult= mysqli_query($cxn,$DeleteQuery) or die ("Error1!");
}
if(isset($_POST['No']))
{
echo "No!";
}
}
}
?>
</body></html>
Please modify this code so that i will get 2 option value from this code
<select name="student_class1" class="input-xlarge" >
<option value="null">--Select Class---</option>
<?php $sel_service = "select * from all_services where school_id='$school_id'";
$sel_service= mysql_query($sel_service);
while($display_class= mysql_fetch_assoc($sel_service))
{ ?>
<option value="<?php echo $display_class['sub_cat_id']; ?>"><?php echo ucfirst($display_class['sub_cat_name']); ?></option>
<?php } ?>
student_class1 giving me value sub_cat_id
i want
student_class2 will give me sub_cat_name
iwant both values by one select
plz modify it
i already spent my whole sunday on this problem
something like?
<form action="" method="get" accept-charset="utf-8">
<select name="student_class1" class="input-xlarge" >
<?php
$sel_service = "select * from all_services where school_id='$school_id'";
$sel_service= mysql_query($sel_service);
while ($row = mysql_fetch_assoc($sel_service)) {
?>
<option value="null">--Select Class---</option>
<option value="<?php echo $row['sub_cat_id']; ?>"></option>
<option value="<?php echo $row['sub_cat_name']; ?>"></option>
<?php
}
?>
</select>
</form>
I'm developing a webpage with a select list that contains images.
I already have this:
When I select an image name in the list the image will be displayed in the div below.
<?php
// Create connection
$con=mysqli_connect("******","***","***","charts");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<form method="post" action="index.php" id="nano" name="nano">
<p>
<select name="SelectBox" id="SelectBox" onchange="this.form.submit()">
<?php if($_POST['submitted'] == true){ ?>
<?php
$result = mysqli_query($con,"SELECT * FROM Nano WHERE IMAGE_NAME ='". $_POST['SelectBox']."'");
while($row = mysqli_fetch_array($result))
{ ?>
<option selected="selected" value="<?php echo $row['IMAGE_NAME'] ?>">
<?php echo $row['IMAGE_PARAMETER'] ?>
</option>
<?php } ?>
<?php echo $_POST['SelectBox']; ?></option>
<?php } else{ ?>
<?php
$result = mysqli_query($con,"SELECT TOP * FROM Nano");
while($row = mysqli_fetch_array($result))
{
?>
<option selected="selected" value="<?php echo $row['IMAGE_NAME'] ?>">
<?php echo $row['IMAGE_PARAMETER'] ?>
</option>
<?php
$var1 = $row['IMAGE_NAME']; ?>
<?php
}
?>
<?php } ?>
<option value="" disabled="disabled"> -------- </option>
<?php
$result = mysqli_query($con,"SELECT * FROM Nano");
while($row = mysqli_fetch_array($result))
{ $values[] = $row['IMAGE_NAME'];
?>
<option value="<?php echo $row['IMAGE_NAME'] ?>">
<?php echo $row['IMAGE_PARAMETER'] ?>
</option>
<?php }?>
</select>
<input type="hidden" name="submitted" id="submitted" value="true" />
</p>
<?php if($_POST['submitted'] == true){ ?>
<p><img src="Images\Nano\<?php echo $_POST['SelectBox']?>" width="953" height="600" /></p>
<?php }else { ?>
<p><img src="Images\Nano\<?php print_r($values[0]) ?>" width="953" height="600" /></p>
<?php } mysqli_close($con);?>
</form>
</div>
I want when I move down in the select list the picture will change and not when I click on it in the select list.
In your case, you have to bind hover event to option, but there is no way to do what you want using native select control. The native one only answers when you click a different option from previous.
However, you can simulate a select control using html&css&js, that way when your cursor move down the simulated option(which might be a div or something), you can bind event handlers to it and display the name.