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