Welcome to WebmasterWorld Guest from 184.72.177.182

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

MySQL Select Problems in PHP

     
5:12 pm on Jul 25, 2003 (gmt 0)

New User

10+ Year Member

joined:July 24, 2003
posts:26
votes: 0


Hi, I've got a problem when querying a MySQL database in PHP: When I get the data from a Select statement with mysql_query() and want to print it on the page, I get "RessourceID #2" as the data that is in the $Resultat variable. Anyone can tell me why? Thanx!

Here's part of the code:
----------------------------------------------------
if (!($Lien = mySql_connect("****", "****", ""))){
exit();
}

if (!(mySql_select_db("cargo",$Lien)))
{
exit();
}

$requete="SELECT id FROM transporteurs WHERE Nom_entre='$entreprise' ORDER BY 'id' DESC ";

$Resultat = mySql_query($requete,$Lien);

if (!($Resultat)) {
if (mySql_errno() == 1062){
redirect("usagerno.php?entreprise=$entreprise");
}else{
redirect("wrong.php?message1=$mess1&message2=$mess2&message3=$mess3&entreprise=$entreprise");

}
}

$num=$Resultat;
echo($num);

5:26 pm on July 25, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 1, 2002
posts:1834
votes: 0


$requete="SELECT id FROM transporteurs WHERE Nom_entre='$entreprise' ORDER BY 'id' DESC ";

$Resultat = mySql_query($requete,$Lien);

You need to now use that resource id to get at the data you pulled, i.e.

while ($row = mysql_fetch_array($Resultat)) {
/* whatever you want it to do */
}

WBF

5:29 pm on July 25, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:June 3, 2002
posts:169
votes: 0


Hi Kronos,

the problem is that $Resultat is a resource identifier and not the data per se, so you have to add a step and use the function mysql_fetch_array() [ca2.php.net] to retrieve the data.

Bonne chance.

mavherick

[added]too slow! What WBF said![/added]

11:43 am on July 26, 2003 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


Use this - it's a null test, should work

if (!($TheResultat = mySql_fetch_row(mySql_query($requete,$Lien))))

then wehn you want to output, remember to pick index 0 of the array:


$num=$TheResultat[0];
echo($num);