Ho una tabella mysql con user_name e user_corso
per esempio
andrea- ginnastica
andrea - montagna
andrea - mare
pippo - ginnastica
pippo - mare
faccio la ricerca su montagna ma non so come ricavare che pippo non ha questo valore.... un aiuto? grazie
Ho una tabella mysql con user_name e user_corso
per esempio
andrea- ginnastica
andrea - montagna
andrea - mare
pippo - ginnastica
pippo - mare
faccio la ricerca su montagna ma non so come ricavare che pippo non ha questo valore.... un aiuto? grazie
codice:SELECT DISTINCT c1.user_name FROM corsi c1 LEFT JOIN corsi c2 ON c1.user_name=c2.user_name AND c2.user_corso='montagna' WHERE c2.user_corso IS NULL;
optime, sei gentilissimo
SELECT DISTINCT c1.user_nome FROM vt_formaz_corsi c1 LEFT JOIN vt_formaz_corsi c2 ON c1.user_nome=c2.user_nome AND c2.user_corso='montagna'
con questa query mi estrae tutti i nomi presenti nella tabella, proverò a fare altre prove
no, con quella estrae solo quelli che NON hanno montagna
ti posto l'intero codice... ora così mi estrae valori a caso
<?php
include 'DBController.php';
$db_handle = new DBController();
$countryResult = $db_handle->runQuery('SELECT DISTINCT user_corso FROM '.(string)$database4.' ORDER BY user_corso ASC');
?>
<form id="myform" method="POST" name="search" action="formaz_scadenze_corsinonfatti.php">
<div class="dropdown" id="demo-grid" style="p-3 w-100">
<div class="search-box">
<select id="defaultSelect" class="form-select" name="country[]" style="p-3 w-100">
<option value="0" selected="selected">Corsi</option>
<?php
if (! empty($countryResult)) {
foreach ($countryResult as $key => $value) {
echo '<option value="' . $countryResult[$key]['user_corso'] . '">' . $countryResult[$key]['user_corso'] . '</option>'; } } ?>
</select><br> <br>
<button id="Filter">Search</button>
</div>
</div></li></ul></div></div>
<?php
if (! empty($_POST['country'])) { ?>
<table id="example" class="table table-striped" style="width:100%" Name="$pagina">
<thead>
<tr>
<th><strong>Nome</strong></th>
<th><strong>Corso</strong></th>
</tr>
</thead>
<tbody>
<?php //$stmtsc = $DB_con->prepare('SELECT DISTINCT c1.user_corso, c1.user_nome FROM vt_formaz_corsi c1 LEFT JOIN vt_formaz_corsi c2 ON c1.user_nome=c2.user_nome AND c2.user_corso='.(string)$mont.' where c2.user_corso IS NULL');
$query = "SELECT DISTINCT c1.user_corso, c1.user_nome FROM vt_formaz_corsi c1";
$i = 0;
$selectedOptionCount = count($_POST['country']);
$selectedOption = "";
while ($i < $selectedOptionCount) {
$selectedOption = $selectedOption . "'" . $_POST['country'][$i] . "'";
if ($i < $selectedOptionCount - 1) {
$selectedOption = $selectedOption . ", ";
} $i ++; }
$query = $query . " LEFT JOIN vt_formaz_corsi c2 ON c1.user_nome=c2.user_nome AND c2.user_corso=" . $selectedOption . " where c2.user_corso IS NULL ";
$result = $db_handle->runQuery($query); }
if (! empty($result)) { foreach ($result as $key => $value) { ?>
<tr><td><div class="col"><?php echo $result[$key]['user_nome']; ?></div></td>
<td><div class="col"><?php echo $result[$key]['user_corso']; ?></div></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
</div>
</form>
-----
così invece funziona correttamente selezionando quelli che hanno svolto il corso
<?php
if (! empty($_POST['country'])) { ?>
<table id="example" class="table table-striped" style="width:100%" Name="$pagina">
<thead>
<tr>
<th><strong>Nome</strong></th>
<th><strong>Corso</strong></th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * from vt_formaz_corsi";
$i = 0;
$selectedOptionCount = count($_POST['country']);
$selectedOption = "";
while ($i < $selectedOptionCount) {
$selectedOption = $selectedOption . "'" . $_POST['country'][$i] . "'";
if ($i < $selectedOptionCount - 1) {
$selectedOption = $selectedOption . ", ";
} $i ++; }
$query = $query . " WHERE user_corso in (" . $selectedOption . ")";
$result = $db_handle->runQuery($query); }
if (! empty($result)) { foreach ($result as $key => $value) { ?>
<tr><td><div class="col" id="user_data_1"><?php echo $result[$key]['user_nome']; ?></div></td>
<td><div class="col" id="user_data_2"><?php echo $result[$key]['user_corso']; ?></div></td>
</tr>
<?php } ?>
</tbody>
</table>
<?php } ?>
risolto..... errore mio di punteggiatura... ora funziona grazie
optime!![]()