xProteuSx Posted November 16, 2006 Share Posted November 16, 2006 I am sending a query to my DB and the output is "Resource #3" The code is as follows:<?phpinclude ("dbconnect.php"); //connect to the DB$emailquery = "SELECT users_email FROM `users` WHERE `users_handle` LIKE '%Proteus%'";$email_result = mysql_query($emailquery) or die ("The query caused the following error:<br><br>" . mysql_error());echo ("$email_result");?>What does this mean? I cannot figure it out ... Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/ Share on other sites More sharing options...
obsidian Posted November 16, 2006 Share Posted November 16, 2006 When you run a query with a function such as mysql_query(), a resource [b]to[/b] the result set is returned, not the results themselves. You have to then retrieve just the data you are after. So, in a case like yours, you'd want to do something like this:[code]<?php$sql = mysql_query("SELECT users_email FROM users WHERE users_handle LIKE '%Proteus%'");// see if your result holds any recordsif (mysql_num_rows($sql) > 0) { // It does, so let's display them: while ($row = mysql_fetch_array($sql)) { echo "$row[users_email]<br />\n"; }}?>[/code]Hope this helps. Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/#findComment-125335 Share on other sites More sharing options...
printf Posted November 16, 2006 Share Posted November 16, 2006 [b]$email_result[/b] is a resource handle, that you use to fetch the result, it is not the result handle![code]<?phpinclude ("dbconnect.php"); //connect to the DB$emailquery = "SELECT users_email FROM `users` WHERE `users_handle` LIKE '%Proteus%'";$email_result = mysql_query($emailquery) or die ("The query caused the following error: " . mysql_error());$result = mysql_fetch_assoc ( $email_result );echo $result['users_email'];?>[/code]Also don't do stuff like...[code]echo ( "junk" );[/code][b]echo[/b] is not a function, it's [b]language construct[/b], so using [b]()[/b], is not proper coding, even if it does work[b].[/b] Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/#findComment-125336 Share on other sites More sharing options...
printf Posted November 16, 2006 Share Posted November 16, 2006 // deleted, double post Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/#findComment-125337 Share on other sites More sharing options...
xProteuSx Posted November 16, 2006 Author Share Posted November 16, 2006 obsidian, printf, thanks so much for your replies. Both methods work. I wish I knew about 'mysql_fetch_assoc' earlier, but my book does not mention this function. I guess that's what happens when you can only afford a MySQL book written in 2000. Six years is a long time for something like MySQL ... Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/#findComment-125378 Share on other sites More sharing options...
SharkBait Posted November 16, 2006 Share Posted November 16, 2006 Check out www.php.netSince it is the manual for PHP and has all the functions you could want.. and more! Quote Link to comment https://forums.phpfreaks.com/topic/27403-sql-query-result-resource-3/#findComment-125380 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.