homepage Welcome to WebmasterWorld Guest from 54.205.144.54
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
MySQL Select Problems in PHP
Kronos




msg:1299969
 5:12 pm on Jul 25, 2003 (gmt 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);

 

willybfriendly




msg:1299970
 5:26 pm on Jul 25, 2003 (gmt 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

mavherick




msg:1299971
 5:29 pm on Jul 25, 2003 (gmt 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]

vincevincevince




msg:1299972
 11:43 am on Jul 26, 2003 (gmt 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);

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved