Welcome to WebmasterWorld Guest from 54.167.174.11

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

MySQL Select Problems in PHP

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

10+ Year Member



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 Jul 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$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 Jul 25, 2003 (gmt 0)

10+ Year Member



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 Jul 26, 2003 (gmt 0)

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



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);