Lamez Posted December 18, 2007 Share Posted December 18, 2007 alright I have googled my problem in hope of looking for a solution, but I found nothing. I am trying to pull the email from the user table for the user. but I get this: Resource id #20 for the email output what does it mean? here is my query: $email = mysql_query("SELECT email FROM ".TBL_USERS." WHERE username = '$uname'"); am I doing somthing wrong? Quote Link to comment Share on other sites More sharing options...
chigley Posted December 18, 2007 Share Posted December 18, 2007 Show us some more code? Where you try to echo the $email variable? It sounds like you're not fetching a result from the query. Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 oh ok, this is for a members list (if you would like to see it in action: http://www.lamezz.com/user/viewmembers.php?sort=online, user: test1 pass:test) anyways here is the whole function /*Sorts by Online*/ function displayOnline(){ global $database; $q = "SELECT username,timestamp " ."FROM ".TBL_ACTIVE_USERS." ORDER BY timestamp DESC,username"; /*$q = "SELECT username, timestamp " ."FROM".TBL_ACTIVE_USERS. "INNER JOIN".TBL_USERS."ON".TBL_ACTIVE_USERS.username "=" .TBL_USERS.email */ $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_num_rows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; //Table's Specs echo "<tr>\n"; echo "<td valign=\"bottom\"><strong>Username</strong></td>\n"; //Username Column echo "<td width=\"80\" valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Email</strong></td>\n"; //Email Column echo "<td valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Status</strong></td>\n"; //Status Column echo "</tr>\n"; echo "<tr>\n"; echo "<td height=\"1\" colspan=\"5\" align=\"center\" valign=\"top\"><div class=\"dot\"></div></td>\n"; //Dotted Line echo "</tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $email = mysql_query("SELECT email FROM ".TBL_USERS." WHERE username = 'email'"); $time = mysql_result($result,$i,"timestamp"); echo "<tr>\n"; echo "<td><a href=\"userinfo.php?user=$uname\">$uname</a><br></td>\n"; echo "<td> </td>\n"; echo "<td>$email</td>\n"; echo "<td> </td>\n"; echo "<td align=\"left\">\n"; /* Tells the if they are online or offline */ $query = mysql_query("SELECT u.username FROM users u INNER JOIN active_users a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username='$uname'")or die(mysql_error()); if (mysql_num_rows($query) > 0){ echo "<font color=\"#04db04\">Online</font>"; } else { echo "<font color=\"#FF0000\">Offline</font>"; } } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } hope that helps you to help me! Quote Link to comment Share on other sites More sharing options...
chigley Posted December 18, 2007 Share Posted December 18, 2007 <?php list($email) = mysql_fetch_row(mysql_query("SELECT email FROM ".TBL_USERS." WHERE username = 'email'")); ?> There You weren't actually obtaining the result of the query. Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 now there is no output at all. I am completly new to MySQL query, this was my first Quote Link to comment Share on other sites More sharing options...
chigley Posted December 18, 2007 Share Posted December 18, 2007 <?php $email = mysql_query("SELECT email FROM ".TBL_USERS." WHERE username = 'email'") or die(mysql_error()); list($email) = mysql_fetch_row($email); ?> Try that. I'm assuming the rest of your code is fine btw.. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 Here is a quick and dirty crash course, of course there are many ways, this is just one, but it lists each step. $query2 = "SELECT column FROM table WHERE column = '$name'"; //build the query $result2 = mysql_query ($query2) or die ("Error in query: $query2. " . mysql_error()); //execute the query, get the Resource number in $result2 variable if (mysql_num_rows ($result2) > 0) { //see if something was found while ($row2 = mysql_fetch_object ($result2)) { //get the info from that result using a mysql_fetch statement Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 ok I am getting errors about my brackets, here is what I am using as my query and result $eq = "SELECT email FROM ".TBL_USERS." WHERE email = '$uname'"; //build the query $email = mysql_query ($eq) or die ("Error in query: $eq. " . mysql_error()); //execute the query, get the Resource number in $result2 variable if (mysql_num_rows ($email) > 0) { //see if something was found while ($row2 = mysql_fetch_object ($email) //get the info from that result using a mysql_fetch statement } am I doing it wrong, maybe If I explain better what I am trying to do: I am trying to pull the column email from the users table, and place it with the matching username in the active users table. Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 Missing a end ) here while ($row2 = mysql_fetch_object ($email)) <--- and you removed the { opening bracket. Then you need your code after that and a closing bracket } Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 ok now I get another error about I have a unexpected } on like 166 /*Sorts by Online*/ function displayOnline(){ global $database; $q = "SELECT username,timestamp " ."FROM ".TBL_ACTIVE_USERS." ORDER BY timestamp DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_num_rows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table width=\"550\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; //Table's Specs echo "<tr>\n"; echo "<td valign=\"bottom\"><strong>Username</strong></td>\n"; //Username Column echo "<td width=\"80\" valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Email</strong></td>\n"; //Email Column echo "<td valign=\"bottom\"> </td>\n"; //Table Spacer echo "<td valign=\"bottom\"><strong>Status</strong></td>\n"; //Status Column echo "</tr>\n"; echo "<tr>\n"; echo "<td height=\"1\" colspan=\"5\" align=\"center\" valign=\"top\"><div class=\"dot\"></div></td>\n"; //Dotted Line echo "</tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $eq = "SELECT email FROM ".TBL_USERS." WHERE email = '$uname'"; //build the query $email = mysql_query ($eq) or die ("Error in query: $eq. " . mysql_error()); //execute the query, get the Resource number in $result2 variable $time = mysql_result($result,$i,"timestamp"); if (mysql_num_rows ($email) > 0) { //see if something was found while ($row2 = mysql_fetch_object ($email)) //get the info from that result using a mysql_fetch statement } echo "<tr>\n"; echo "<td><a href=\"userinfo.php?user=$uname\">$uname</a><br></td>\n"; echo "<td> </td>\n"; echo "<td>$email</td>\n"; echo "<td> </td>\n"; echo "<td align=\"left\">\n"; /* Tells the if they are online or offline */ $query = mysql_query("SELECT u.username FROM users u INNER JOIN active_users a ON a.username=u.username WHERE a.timestamp < (NOW() - INTERVAL 5 MINUTE) AND u.username='$uname'")or die(mysql_error()); if (mysql_num_rows($query) > 0){ echo "<font color=\"#04db04\">Online</font>"; } else { echo "<font color=\"#FF0000\">Offline</font>"; } } echo "</td>\n"; echo "</tr>\n"; echo "</table>\n"; } what is wrong..here is my whole code here is my query $eq = "SELECT email FROM ".TBL_USERS." WHERE email = '$uname'"; //build the query $email = mysql_query ($eq) or die ("Error in query: $eq. " . mysql_error()); //execute the query, get the Resource number in $result2 variable if (mysql_num_rows ($email) > 0) { //see if something was found while ($row2 = mysql_fetch_object ($email)) //get the info from that result using a mysql_fetch statement } //166 Quote Link to comment Share on other sites More sharing options...
revraz Posted December 18, 2007 Share Posted December 18, 2007 You are still missing the opening { while ($row2 = mysql_fetch_object ($email)) { Quote Link to comment Share on other sites More sharing options...
Lamez Posted December 18, 2007 Author Share Posted December 18, 2007 right, but when I do that anything in between the {} are hidden here is what I have so I can get some sort of output if (mysql_num_rows ($email) > 0) //see if something was found while ($row2 = mysql_fetch_object ($email)) { }//get the info from that result using a mysql_fetch statement but then I still get a Resource id #20 Quote Link to comment Share on other sites More sharing options...
trq Posted December 18, 2007 Share Posted December 18, 2007 Here is a much clearer example of how it should be done. <?php $sql = "SELECT email FROM ".TBL_USERS." WHERE email = '$uname' LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo $uname . "'s email address is " . $row['email']; } else { echo "No results found"; } } else { echo mysql_error() . "<br />$sql"; } ?> You do not need a while loop if your only expecting 1 result. Quote Link to comment 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.