j'ai encore un probleme concernant une requête SQL
le Script suivant me permet à partir d'un produit de générer une ou plusieurs variantes.
<?php
require_once __DIR__ . '/connection.php';
$product = 'SELECT * FROM product WHERE id = '.$prodId;
$req = $dbConnect->query($product);
$prod = $req->fetch(PDO::FETCH_ASSOC);
//$isAdmin = (isset($_SESSION['role']) && $_SESSION['role'] === 'admin');
?>
<div id="produits">
<div class="produit h-product" id="produit_<?php echo $prod['id'] ?>" align="center" style="margin-right:58%">
<form method="post" action="formular.php" autocomplete="off" name="<?php echo $prod['id'] ?>">
<input type="hidden" name="id" value="<?php echo $prod['id'] ?>">
<table border="0" cellpadding="0">
<tr>
<td style=" color:#FFFFFF ; background-color:#860000; width:0%; height:13px; border:3px solid #860000;">PRODUKT</td>
</tr>
<tr class="row9">
<td class="column0 style24 null style27" colspan="4" rowspan="8">
<img style=" z-index: 1; left: 40px; top: 10px; width: 220px; height: 220px;"
src="images/<?php echo $prod['path'] ?>"><input type="hidden" name="selected_photo"
value="<?php echo $prod['path'] ?>"></td>
<td class="column4 style10 s">a</td>
<td class="column5 style19 n" style="font-size:15px"><input type="text" name="a" size="6" maxlength="4" value="<?php echo $prod['a'] ?>"></td>
</tr>
<tr class="row10">
<td class="column4 style11 s">b</td>
<td class="column5 style20 n" style="font-size:15px"><input type="text" name="b" size="6" maxlength="4" value="<?php echo $prod['b'] ?>"></td>
</tr>
<tr class="row11">
<td class="column4 style11 s">c</td>
<td class="column5 style20 null" style="font-size:15px"><input type="text" name="c" size="6" maxlength="4" value="<?php echo $prod['c'] ?>">
</td>
</tr>
<tr class="row12">
<td class="column4 style11 s">d</td>
<td class="column5 style20 null" style="font-size:15px"><input type="text" name="d" size="6" maxlength="4" value="<?php echo $prod['d'] ?>">
</td>
</tr>
<tr class="row13">
<td class="column4 style11 s">e</td>
<td class="column5 style20 null" style="font-size:15px"><input type="text" name="e" size="6" maxlength="4" value="<?php echo $prod['e'] ?>">
</td>
</tr>
<tr class="row17" >
<td class="column0 style14 s" style="font-size:14px; text-align:center;font-weight:bold"><input type="reset" name="affacer_donnée" value="effacer"></td>
<td class="column1 style40 n style42" colspan="2"></td>
<td class="column3 style15 s" style="font-weight:bold">
<input type="checkbox" name="variant"> Ajouter une Variante </td>
<td class="column4 style40 n style41" colspan="2">
<input type="submit" name="save_product" value="Sauvegarder">
</td>
</tr>
</tbody>
</table>
</form>
</div>
<?php
// Variante est gêneré a ce niveau
$variants = 'SELECT * FROM variants WHERE img_id = '.$prodId;
$req2 = $dbConnect->query($variants);
while ($variant = $req2->fetch(PDO::FETCH_ASSOC)) {
?>
<div class="produit" id="produit_<?php echo $variant['id'] ?>" align="center" style="margin-right:68%">
<form method="post" action="formular.php" name="<?php echo $variant['id'] ?>">
<input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
<table border="0" cellpadding="0">
<td style=" color:#FFFFFF ; background-color:#004B27; width:0%; height:13px; border:3px solid #004B27;">VARIANTE</td>
<tr class="row9">
<td class="column0 style24 null style27" colspan="4" rowspan="8">
<img style=" z-index: 1; left: 40px; top: 10px; width: 220px; height: 220px;" src="images/<?php echo $prod['path'] ?>"><input type="hidden" name="selected_photo" value="<?php echo $prod['path'] ?>" ></td>
<td class="column4 style10 s">a</td>
<td class="column5 style19 n"style="font-size:15px"><input type="text" name="a" size="6" maxlength="4" value="<?php echo $variant['a'] ?>" ></td>
</tr>
<tr class="row10">
<td class="column4 style11 s">b</td>
<td class="column5 style20 n"style="font-size:15px"><input type="text" name="b" size="6" maxlength="4" value="<?php echo $variant['b'] ?>" ></td>
</tr>
<tr class="row11">
<td class="column4 style11 s">c</td>
<td class="column5 style20 null"style="font-size:15px"><input type="text" name="c" size="6" maxlength="4" value="<?php echo $variant['c'] ?>" ></td>
</tr>
<tr class="row12">
<td class="column4 style11 s">d</td>
<td class="column5 style20 null"style="font-size:15px"><input type="text" name="d" size="6" maxlength="4" value="<?php echo $variant['d'] ?>" ></td>
</tr>
<tr class="row13">
<td class="column4 style11 s">e</td>
<td class="column5 style20 null" style="font-size:15px"><input type="text" name="e" size="6" maxlength="4" value="<?php echo $variant['e'] ?>" ></td>
</tr>
<tr class="row17">
<td class="column0 style14 s" style="font-size:14px; text-align:center;font-weight:bold">
<input type="reset" name="daten_loeschen" value="Zurücksetzen">
</td>
<td class="column1 style40 n style42" colspan="2">
</td>
<td class="column3 style15 s">
</td>
<td class="column4 style40 n style41" colspan="2">
<input type="submit" name="save_variant" value="Speichern">
</td>
</tr>
</form>
<tr class="row17">
<td class="column0 style14 s"></td>
<td class="column1 style40 n style42" colspan="2">
<form method="post" action="delete_variant.php" name="delete_<?php echo $variant['id'] ?>">
<input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
<input type="hidden" name="img_id" value="<?php echo $prod['id'] ?>">
<input type="hidden" name="img_path" value="<?php echo $prod['path'] ?>">
<input type="hidden" name="type" value="variant">
<input type="hidden" name="location" value="<?php echo $_SERVER['REQUEST_URI'] ?>">
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>">
<input type="hidden" name="sessionID" value="<?php echo $_SESSION['sessionID'] ?>">
<input type="hidden" name="time" value="<?php echo $_SESSION['time'] ?>">
<input type="submit" name="select_variant" value="Löschen" style="align:center">
</form>
</td>
<td class="column3 style15 s" style="font-size:14px; text-align:center;font-weight:bold">
<form method="post" action="drucker.php" name="<?php echo $variant['id'] ?>">
<input type="hidden" name="id" value="<?php echo $variant['id'] ?>">
<input type="hidden" name="img_id" value="<?php echo $prod['id'] ?>">
<input type="hidden" name="img_path" value="<?php echo $prod['path'] ?>">
<input type="hidden" name="type" value="variant">
<input type="hidden" name="location" value="<?php echo $_SERVER['REQUEST_URI'] ?>">
<input type="hidden" name="user_id" value="<?php echo $_SESSION['user_id'] ?>">
<input type="hidden" name="sessionID" value="<?php echo $_SESSION['sessionID'] ?>">
<input type="hidden" name="time" value="<?php echo $_SESSION['time'] ?>">
<input type="submit" name="select_variant" value="Auswählen" style="align:center">
</form>
</td>
<td class="column4 style40 n style41" colspan="2">
</td>
</tr>
</tbody>
</table>
</div>
<?php
}
?>
actuelle lorsqu'un administrateur ou un simple user une ou plusieurs variantes génére tous les autresusers pevent voire ce que l'administrateur et le User ont générer.
Je souhaiterai bien que si un user des variantes génére seul l'administrateur et lui peuvent
voire ce qu'il a générer et non les autres users.
mais il faut noter que ce que l'administrateur génére doit être vus par tous les users.
si je me suis mal exprimé a un niveau pardon ne pas hesiter.
Voici a quoi ressemble les tableaux users et variants
users.sql
CREATE TABLE `users` (
`user_id` int(11) NOT NULL,
`login` varchar(250) NOT NULL,
`pass` varchar(250) NOT NULL,
`role` varchar(256) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
variants.sql
CREATE TABLE `variants` (
`id` int(16) NOT NULL,
`img_id` int(16) NOT NULL,
`user_id` int(11) NOT NULL,
`a` int(11) DEFAULT '0',
`b` int(11) DEFAULT '0',
`c` int(11) DEFAULT '0',
`d` int(11) DEFAULT '0',
`e` int(11) DEFAULT '0',
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Merci bien de vos propositions