Retrieve data from second sql table inside a modal using php
Retrieve data from second sql table inside a modal using php
So the question would be, how can I retrieve data for Locatie (drop-down list) inside the modal if the data is in a second table named locationstbl with the column named address in sql.
There might be some way to use JOIN or something like that just to display the data I need in that dropdown list ?
Thank you.
Here's the code.
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>#</th>
<th>Locatie</th>
<th>Serie Aparat</th>
<th>Tip Joc</th>
<th>Cabinet</th>
<th>Data Expirare</th>
<th>Actiuni</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT location, serial, game_type, cabinet, date
FROM all_machines
ORDER BY location ASC";
$result = $conn->query($sql);
$resultNum = mysqli_num_rows($result);
$counter = 1;
if ($resultNum > 0) {
while ($row = mysqli_fetch_assoc ($result)){
$location = $row['location'];
$serial = $row['serial'];
$game_type = $row['game_type'];
$cabinet = $row['cabinet'];
$date = $row['date'];
?>
<tr>
<td><?php echo $counter++;?></td>
<td><?php echo $location;?></td>
<td><?php echo $serial;?></td>
<td><?php echo $game_type;?></td>
<td><?php echo $cabinet;?></td>
<td><?php echo $date;?></td>
<td>
<!-- Table Action Buttons -->
<a href="#editare<?php echo $serial;?>" data-toggle="modal">
<button type='button' class='btn btn-success btn-sm' data-whatever="<?php echo $serial;?>">Editare</button></a>
<a href="#delete<?php echo $serial;?>" data-toggle="modal">
<button type='button' class='btn btn-danger btn-sm' >Sterge</button></a>
<a href='detalii.php?id=<?php echo $serial;?>'>
<button type='button' class='btn btn-info btn-sm'>Detalii</button></a>
</td>
<!--Delete Modal -->
<div id="delete<?php echo $serial; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Confirmati stergerea</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<input type="hidden" name="serial" value="<?php echo $serial; ?>">
<div class="alert alert-danger"><p>Sunteti sigur ca doriti stergerea seriei <strong><?php echo $serial; ?></strong> ?</p>
</div>
</div>
<div class="modal-footer">
<a class='btn btn-danger btn-sm' href="delete.php?id=<?php echo $serial;?>">Sterge</a>
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">Anuleaza</button>
</div>
</div>
</div>
</div>
<!--Edit Modal -->
<div id="editare<?php echo $serial; ?>" class="modal fade" role="dialog">
<div class="modal-dialog" role="document">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Editare Serie: <strong><?php echo $serial; ?></strong></h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<form method="POST" action="edit-mac.php?id=<?php echo $serial;?>">
<div class="form-group">
<div class="form-row">
<!-- Select data from locationstbl -->
<div class='col-md-6'>
<label>Locatie</label>
<select name='location' class='form-control input-sm'>
<option></option>
</select>
<span class='help-block'></span>
</div>
<div class="col-md-6">
<label for="serial">Serie</label>
<input type="text" class="form-control" id="serialup" name="serialup" value="<?php echo $serial; ?>">
<span class="help-block"></span>
</div>
<div class="col-md-6">
<label for="serial">Tip Joc</label>
<input type="text" class="form-control" id="game_type" name="game_type" value="<?php echo $game_type; ?>">
<span class="help-block"></span>
</div>
<div class="col-md-6">
<label for="serial">Cabinet</label>
<input type="text" class="form-control" id="cabinet" name="cabinet" value="<?php echo $cabinet; ?>">
<span class="help-block"></span>
</div>
<div class="col-md-6">
<label for="date">Data expirare</label>
<input class="form-control" id="date" type="text" autocomplete="off" name="date" value="<?php echo $date; ?>" placeholder="LL-AAAA">
<span class="help-block"></span>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-success btn-sm">Actualizeaza</button>
<button type="button" class="btn btn-primary btn-sm" data-dismiss="modal">Anuleaza</button>
</form>
</div>
</div>
</div>
</div>
</tr>
<?php
}
}
?>
</tbody>
</table>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.