Jump to content

Catchable fatal error: Object of class mysqli_result could not be converted to..


mikhell

Recommended Posts

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  :wtf:

 

how can i do it ?  :confused:

Link to comment
Share on other sites

//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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.