I have two database tables, released_movies and upcoming_movies. I need to display the field rel_movies in release_movies table and up_movies field in upcoming_movies table inside a single dropdown list. Below is my code.
<select name="film" class="form-control">
<?php
include "connection.php";
$sql="select rel_movies from released_movies";
$sqlr=$con->query($sql);
while($row=$sqlr->fetch_assoc())
{
?>
<option value="<?php echo $row['rel_movies'];?>"><?php echo $row['rel_movies'];?></option>
<?php
}
?>
</select>
I have no idea how to display up_movies field into it. Is this possible .Thanks in advance.
You may use UNION in mysql for getting records from more than one table.
In your case you may use UNION for getting released as well as upcoming movies, no need of execution of two MySQL query.
<select name="film" class="form-control">
<?php
include "connection.php";
$sql="select rel_movies as movies_name from released_movies
UNION select up_movies as movies_name from upcoming_movies";
$sqlr=$con->query($sql);
while($row=$sqlr->fetch_assoc())
{
?>
<option value="<?php echo $row['movies_name'];?>"><?php echo $row['movies_name'];?></option>
<?php
}
?>
</select>
More info about UNION: UNION
Try this
<?php include "connection.php"; ?>
<select name="film" class="form-control">
<?php
$sqlr="select rel_movies from released_movies";
$sqlrr=$con->query($sqlr);
while($row=$sqlrr->fetch_assoc()) { ?>
<option value="<?php echo $row['rel_movies'];?>">
<?php echo $row['rel_movies'];?>
</option>
<?php }
$sqlu="select up_movies from upcoming_movies";
$sqluu=$con->query($sqlu);
while($rowu=$sqluu->fetch_assoc()){ ?>
<option value="<?php echo $rowu['up_movies'];?>">
<?php echo $rowu['up_movies'];?>
</option>
<?php } ?>
</select>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With