mikhell Posted October 13, 2010 Share Posted October 13, 2010 Hi, i try to get all groupe that my user is subscribe and show it in a drop list. There is my code : <?php //selectionner l'usager $user = $_SESSION['username']; //aller chercher le numéro de l'id de l'usager $IDmembre = mysqli_query($connection, "SELECT id_membre FROM membres WHERE username = '$user'"); //regarder dans quels groupes l'usager est inscrit $IDgroupes = mysqli_query($connection, "SELECT id_groupe FROM membres_groupe WHERE id_membre = '$IDmembre'"); //aller chercher les informations des groupes ou l'usager est inscrit while($groupe = mysqli_fetch_array($IDgroupes)){ $infoGroupe = mysqli_query($connection, "SELECT * FROM groupes WHERE id_groupe = '".$groupe['id_groupe']".'"); } //afficher la liste déroulante echo "<select name='groupes_msg' id='groupes_msg'>"; echo "<option value=''>Vos groupes</option>"; while($arrayGroupes = mysqli_fetch_array($infoGroupe)){ echo "<option value='".$arrayGroupes['nom']."'>".$arrayGroupes['nom']."</option>"; } echo "</select>"; ?> it gives me error : Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\unibind\phpInclude\liste_groupe.php on line 7 how can i do it ? Link to comment https://forums.phpfreaks.com/topic/215790-catchable-fatal-error-object-of-class-mysqli_result-could-not-be-converted-to/ Share on other sites More sharing options...
premiso Posted October 13, 2010 Share Posted October 13, 2010 //aller chercher le numéro de l'id de l'usager $IDmembre = mysqli_query($connection, "SELECT id_membre FROM membres WHERE username = '$user'"); $IDmembre = mysqi_fetch_row($connection, $IDMembre); $IDmembre = $IDmembre[0]; $IDgroupes = mysqli_query($connection, "SELECT id_groupe FROM membres_groupe WHERE id_membre = '$IDmembre'"); You needed to fetch the column that you wanted to use in the next query, above is a rough example of what I am talking about. Link to comment https://forums.phpfreaks.com/topic/215790-catchable-fatal-error-object-of-class-mysqli_result-could-not-be-converted-to/#findComment-1121823 Share on other sites More sharing options...
mikhell Posted October 13, 2010 Author Share Posted October 13, 2010 Thnak you for your reply ! i got it ! <?php echo "<select name='groupes_msg' id='groupes_msg'>"; echo "<option value=''>Vos groupes</option>"; //selectionner l'usager $user = $_SESSION['username']; //aller chercher le numéro de l'id de l'usager $IDmembre = mysqli_query($connection, "SELECT id_membre FROM membres WHERE username = '$user'"); $IDarrayMembre = mysqli_fetch_row($IDmembre); //regarder dans quels groupes l'usager est inscrit $IDgroupes = mysqli_query($connection, "SELECT * FROM membres_groupe WHERE id_membre = '$IDarrayMembre[0]'"); //aller chercher les informations des groupes ou l'usager est inscrit while($groupe = mysqli_fetch_array($IDgroupes)){ $arrayGroupe = $groupe['id_groupe']; $infoGroupe = mysqli_query($connection, "SELECT nom FROM groupes WHERE id_groupe = '$arrayGroupe'"); //afficher la liste déroulante $arrayGroupes = mysqli_fetch_array($infoGroupe); for($i = 0; $i <= mysqli_num_rows($infoGroupe); $i++){ echo "<option value='".$arrayGroupes[$i]."'>".$arrayGroupes[$i]."</option>"; } } echo "</select>"; ?> tanx again Link to comment https://forums.phpfreaks.com/topic/215790-catchable-fatal-error-object-of-class-mysqli_result-could-not-be-converted-to/#findComment-1121844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.