refiking Posted January 3, 2008 Share Posted January 3, 2008 What am I doing wrong? I want to retrieve an id from the db. <?php include 'cnt.php'; $ssn = 123456789; $bln = "Doe"; $borid2 = mysql_query("SELECT bor_id FROM Borrowers WHERE ssn = '$ssn' AND bln = '$bln'"); echo $borid2; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/ Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 $borid2 is just a Resource to get to the deta. Use mysql_fetch to actually fetch the data. Either mysql_fetch_array or mysql_fetch_object will do the trick. Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429511 Share on other sites More sharing options...
simcoweb Posted January 3, 2008 Share Posted January 3, 2008 Exactly, if you echo the $borid2 it will just display your query, not the results. $results = mysql_query($borid2) or die(mysql_error()); if($results){ echo $results; } else { echo "There are no results! Help!"; } Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429522 Share on other sites More sharing options...
phpSensei Posted January 3, 2008 Share Posted January 3, 2008 If you are selecting one row, then use mysql_fetch_assoc Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429525 Share on other sites More sharing options...
redarrow Posted January 3, 2008 Share Posted January 3, 2008 read this please <?php //use ?php format as it defualt in php.ini and safe opening for php programming. //database connection //database correct connection format, even theo there other ways...... $db=mysql_connect("localhost or ip or url","name of user","password for user"); $db_result=mysql_select_db("database using",$db); // selecting a standard database query of all entrys. $sql1="SELECT * FROM whatever"; $sql_result1=mysql($sql1); while(list($key,$val)=mysql_fetch_assoc($sql_result1))){ echo "$key <br> $val"; } //The above will list all entry's via $key $val useing the while loop and list function.... // selecting a name via it were clause and other info as needed.... $sql2="SELECT * FROM whatever where name='petter'"; $sql_result2=mysql($sql2); while($row=mysql_fetch_assoc($sql_result2)){ echo " ".$row['name']." <br> ".$row['id']." "; } // The above will echo out the name off petter and only petteres info as stated in the were //clause and any other record needed via the while loop of petter only and it field name $row[''] //asked, example the $row id was added of petters only..... // selecting only id and name via where name='petter' $sql3="SELECT name,id FROM whatever where name='petter'"; $sql3_result=mysql($sql3); while($row=mysql_fetch_assoc($sql_result3))){ echo " ".$row['name']." <br> ".$row['id']." "; } // same as last above example, except we can only see the id and name as it been seleted via //the select query and it in relation with the name petter only set via the were clause........ // selecting only name via where name='petter and using no while loop ... $sql4="SELECT name FROM whatever where name='petter'"; $sql4_result=mysql($sql4); $row=mysql_fetch_assoc($sql_result4)); echo " ".$row['name']." "; // same as last above example, except we can only see the id and name as it been seleted via //the select query and it in relation with the name petter only set via the were clause........ // but also were only getting one result of a name so we dont need a while loop, but if we //wanted to also see the id of petter we should use the while loop........ //WARNING old programming before sessions. //this is bad programming but it still happends belevle it or not, let say we wanted to select //petter info via his id but we have no session set and dont no petters id....... // first we get petters id via one select statement and no while loop........ sql5="SELECT id FROM whatever where name='petter'"; $sql5_result=mysql($sql5); $row1=mysql_fetch_assoc($sql_result5)); //Another select statement to get petters info via the above id select statement... sql6="SELECT * FROM whatever where name='petter' and user_id=' ".$row1['id']." ' "; $sql6_result=mysql($sql6); while($row2=mysql_fetch_assoc($sql_result6)); echo" ".$row2['user_id']." <br> ".$row2['name']." <br> ".$row2['age']." "; } // the above selects the first select statement to get the users id then the secound echo the info............ // what ever way you select users info all you need to do is use any other mysql function like //DELETE,UPDATE in the while loop to do anythink elese you need to do........ //if you got the users id in a session just use that session in a where clause.. my littele tutoral good luck ?> example for u. <?php $sql4="SELECT id FROM whatever where name='petter'"; $sql_result4=mysql($sql4); $row=mysql_fetch_assoc($sql_result4)); echo " ".$row['id']." "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429527 Share on other sites More sharing options...
refiking Posted January 3, 2008 Author Share Posted January 3, 2008 Ok. Here is the updated script: <?php include 'cnt.php'; $ssn = 123456789; $bln = "Doe"; $bor = "SELECT bor_id FROM Borrowers where ssn = $ssn AND bln = $bln"; $bor2 = mysql($bor); $borid = mysql_fetch_assoc($bor2); echo $borid; ?> Here is what it returned: Warning: Wrong parameter count for mysql() in /home/public_html/test/test.php on line 6 Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/public_html/test/test.php on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429545 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 Leave the single quotes around your two variables '$ssn' & '$bln' in your SQL statement. Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429550 Share on other sites More sharing options...
refiking Posted January 3, 2008 Author Share Posted January 3, 2008 Still says the same thing Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429553 Share on other sites More sharing options...
wildteen88 Posted January 3, 2008 Share Posted January 3, 2008 This line: $bor2 = mysql($bor); Should be: $bor2 = mysql_query($bor); Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429557 Share on other sites More sharing options...
refiking Posted January 3, 2008 Author Share Posted January 3, 2008 Ok. Now it returns: Array Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429560 Share on other sites More sharing options...
revraz Posted January 3, 2008 Share Posted January 3, 2008 What exactly do you want? Do you want each item echo'd out? $borid is an array, so if you want to see what's in the array, use print_r($borid); and not echo. Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429562 Share on other sites More sharing options...
wildteen88 Posted January 3, 2008 Share Posted January 3, 2008 You cant echo arrays like you can with strings. You can use print_r to see what your array contains. To retrieve the bor_id from your query use the following: $bor = "SELECT bor_id FROM Borrowers where ssn = '$ssn' AND bln = '$bln'"; $bor2 = mysql_query($bor); $row = mysql_fetch_assoc($bor2); echo $row['bor_id']; Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429564 Share on other sites More sharing options...
Daniel0 Posted January 3, 2008 Share Posted January 3, 2008 Change $borid = mysql_fetch_assoc($bor2); to list($borid) = mysql_fetch_row($bor2); Quote Link to comment https://forums.phpfreaks.com/topic/84333-solved-resource-id4/#findComment-429567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.