ueon Posted January 2, 2012 Share Posted January 2, 2012 $query = mysql_query("SELECT a.*, b.* FROM friendlist a INNER JOIN friendlist b ON (a.friendemail=b.friendemail) INNER JOIN users c ON (b.friendemail = c.EmailAddress) WHERE a.email = 'asdf@gmail.com' AND c.Username LIKE '%carol%' GROUP BY a.id ORDER BY count(*) DESC"); while ($showfriends = mysql_fetch_array($query)) { echo $showfriends['Username']; } and I would get nothing. It produces the correct number of <div> so i know it's getting through, but it's having trouble displaying the entries? Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/ Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 You aren't outputting any divs in your loop, so how would you determine that your query is correct by the number of divs? Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303507 Share on other sites More sharing options...
ueon Posted January 3, 2012 Author Share Posted January 3, 2012 You aren't outputting any divs in your loop, so how would you determine that your query is correct by the number of divs? the query is copy and pasted from my project. in the project, it does have divs Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303520 Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 You aren't outputting any divs in your loop, so how would you determine that your query is correct by the number of divs? the query is copy and pasted from my project. in the project, it does have divs Show all of the relevant code, if you leave stuff out that makes us have to guess. Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303525 Share on other sites More sharing options...
ueon Posted January 3, 2012 Author Share Posted January 3, 2012 You aren't outputting any divs in your loop, so how would you determine that your query is correct by the number of divs? the query is copy and pasted from my project. in the project, it does have divs Show all of the relevant code, if you leave stuff out that makes us have to guess. how would you output the `Username` from table c? c.Username? in the simplest form? Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303533 Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 If username is coming from table c, you will need to specify that in your SQL, right now you are grabbing a.* and b.* in your code, add c.Username to that list. Shouldnt have to change anything else. Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303538 Share on other sites More sharing options...
ueon Posted January 3, 2012 Author Share Posted January 3, 2012 wow, can't believe i didn't see that. That's all i needed, thanks! Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303539 Share on other sites More sharing options...
Zane Posted January 3, 2012 Share Posted January 3, 2012 you should be joining on IDs/inedexes... not a varchar field. Not saying it won't work, but there is definitely more room for errors if you join on varchar. For instance, a single space could keep it from working whereas an id is simply a number. Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303540 Share on other sites More sharing options...
AyKay47 Posted January 3, 2012 Share Posted January 3, 2012 you should be joining on IDs/inedexes... not a varchar field. Not saying it won't work, but there is definitely more room for errors if you join on varchar. For instance, a single space could keep it from working whereas an id is simply a number. To back Zane here, since I did overlook that in your code, joins are most efficient when they join tables by indexes, the purpose of an index in MySQL is to link two tables by an indexed field and possibly restrict certain actions to be done if the indices of two linked tables do not match. Yes it will work, but as Zane stated, all it would take is a space or something small by the user if the query is dependent on user data to throw off the query. Quote Link to comment https://forums.phpfreaks.com/topic/254234-retrieving-database-entries/#findComment-1303543 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.