Php Call to a member function query()
nonowned
Messages postés
4
Statut
Membre
-
nonowned Messages postés 4 Statut Membre -
nonowned Messages postés 4 Statut Membre -
Bonjour,
Voilà, j'ai un projet web à faire dans le cadre de mon DUT informatique, il est pratiquement fini donc là j'optimise un max mon code en enlevant un maximum de copier coller et donc en créant des fonctions mais voilà, j'ai une erreur qui apparait :
[quote]Call to a member function query() on a non-object in .../fotolink/BD/photo.class.php on line 150[/quote]
Bon allons donc voir le fichier photo.class.php.
On y trouve :
[quote]
public function trouver1tag($idPhoto){
$sql = "select * from isTagged where idPhoto =$idPhoto;";
$r = $this->db->query($sql); <------- ligne 150
while($res = mysql_fetch_row($r)){
$t[] = $res;
}
return $t;
}
[/quote]
Bon pour mieux comprendre l'erreur, allons voir l'endroit où j'appelle cette fonction :
[quote]
function affichage($res2){
$photo = new Photo($db);
$tag10 = new Tag($db);
...............
echo"</br>";
if($_SESSION['log']) {
$com=$res2[0];
echo" <a href ='index.php?module=PhotoPublic&action=Commentaire&photo=$com' > voir les commentaires </a>";
}
/* $p=$photo->trouveruser($res2[0]);
foreach($p as $ph){
echo "</br>Utilisateur : ".$ph[1];
} */
echo "</br>Tag : ";
$p=$photo->trouver1tag($res2[0]);
if($p){
foreach($p as $ta){
$tr = $tag10->selectTag($ta[1]);
if($tr){
foreach($tr as $f){
$tag3 = $f[0];
echo" <a href ='index.php?module=PhotoPublic&action=Tag&tag=$tag3' > $f[1]</a>";
}
}
}
[/quote]
La fonction affichage est appelé à cet endroit :
[quote]
echo "<h1> Résultat de votre Recherche</h1>";
if(isset($_POST[submit]) && isset($_POST[what])) {
if($_POST[what] != ""){
$what = $_POST['what'];
$word = $_POST['word'];
require("function.php");
include("BD/DB.class.php");
include("BD/user.class.php");
include("BD/tag.class.php");
include("BD/photo.class.php");
$db = new DB();
$user = new User($db);
......
if($what == "tag"){
$sql = "SELECT * FROM $what WHERE name like '%$word%';";
$query = mysql_query($sql);
while($res = mysql_fetch_row($query)){
$t[] = $res;
}
foreach($t as $ta){
$sql =" select * from photo where public ='1' and idPhoto in ( Select idPhoto from isTagged where idTag = $ta[0]);";
$query = mysql_query($sql);
while($res1 = mysql_fetch_row($query)){
$t2[] = $res1;
}
}
foreach($t2 as $res2){
affichage($res2);
}
}
[/quote]
Si je met directement la fonction affichage à la place de l'appel, ça marche nickel.
Si vous avez des idées, merci de m'en faire part !!
Arnaud
Voilà, j'ai un projet web à faire dans le cadre de mon DUT informatique, il est pratiquement fini donc là j'optimise un max mon code en enlevant un maximum de copier coller et donc en créant des fonctions mais voilà, j'ai une erreur qui apparait :
[quote]Call to a member function query() on a non-object in .../fotolink/BD/photo.class.php on line 150[/quote]
Bon allons donc voir le fichier photo.class.php.
On y trouve :
[quote]
public function trouver1tag($idPhoto){
$sql = "select * from isTagged where idPhoto =$idPhoto;";
$r = $this->db->query($sql); <------- ligne 150
while($res = mysql_fetch_row($r)){
$t[] = $res;
}
return $t;
}
[/quote]
Bon pour mieux comprendre l'erreur, allons voir l'endroit où j'appelle cette fonction :
[quote]
function affichage($res2){
$photo = new Photo($db);
$tag10 = new Tag($db);
...............
echo"</br>";
if($_SESSION['log']) {
$com=$res2[0];
echo" <a href ='index.php?module=PhotoPublic&action=Commentaire&photo=$com' > voir les commentaires </a>";
}
/* $p=$photo->trouveruser($res2[0]);
foreach($p as $ph){
echo "</br>Utilisateur : ".$ph[1];
} */
echo "</br>Tag : ";
$p=$photo->trouver1tag($res2[0]);
if($p){
foreach($p as $ta){
$tr = $tag10->selectTag($ta[1]);
if($tr){
foreach($tr as $f){
$tag3 = $f[0];
echo" <a href ='index.php?module=PhotoPublic&action=Tag&tag=$tag3' > $f[1]</a>";
}
}
}
[/quote]
La fonction affichage est appelé à cet endroit :
[quote]
echo "<h1> Résultat de votre Recherche</h1>";
if(isset($_POST[submit]) && isset($_POST[what])) {
if($_POST[what] != ""){
$what = $_POST['what'];
$word = $_POST['word'];
require("function.php");
include("BD/DB.class.php");
include("BD/user.class.php");
include("BD/tag.class.php");
include("BD/photo.class.php");
$db = new DB();
$user = new User($db);
......
if($what == "tag"){
$sql = "SELECT * FROM $what WHERE name like '%$word%';";
$query = mysql_query($sql);
while($res = mysql_fetch_row($query)){
$t[] = $res;
}
foreach($t as $ta){
$sql =" select * from photo where public ='1' and idPhoto in ( Select idPhoto from isTagged where idTag = $ta[0]);";
$query = mysql_query($sql);
while($res1 = mysql_fetch_row($query)){
$t2[] = $res1;
}
}
foreach($t2 as $res2){
affichage($res2);
}
}
[/quote]
Si je met directement la fonction affichage à la place de l'appel, ça marche nickel.
Si vous avez des idées, merci de m'en faire part !!
Arnaud
A voir également:
- Php Call to a member function query()
- Power query download - Télécharger - Tableur
- Qwerty to azerty - Guide
- Expert php pinterest - Télécharger - Langages
- Video to video - Télécharger - Conversion & Codecs
- Reboot to bootloader - Guide
4 réponses
Un global sur db ?
Kezako ?
Chuis un peu nouveau dans le domaine du php.
Si ça peut aider, voilà le lien de mon site : http://fotolink.free.fr
J'ai seulement testé pour la recherche par tag ( donc ailleurs tout marchera ) donc si vous voulez bien tester faites svp une recherche par tag.
Kezako ?
Chuis un peu nouveau dans le domaine du php.
Si ça peut aider, voilà le lien de mon site : http://fotolink.free.fr
J'ai seulement testé pour la recherche par tag ( donc ailleurs tout marchera ) donc si vous voulez bien tester faites svp une recherche par tag.