adamlacombe Posted August 2, 2009 Share Posted August 2, 2009 I am trying to make it so if someone had added someone as a friend it will look something like this in the database: id=1 from=admin to=test status=1 1 is its been excepted, I have this: <?php $ff=mysql_query("SELECT * FROM friends WHERE `to`='{$row['username']}' AND `status`='1' OR from='{$row['username']}' LIMIT 0,10") or die(mysql_error()); if(mysql_num_rows($ff)>0){ echo "<div class='header'>Friends</div>"; echo "<div class='content'>"; while($friends=mysql_fetch_array($ff)) { $ftname=$friends[to]; $ffname=$friends[from]; if($ffname){ echo "<a href='index.php?action=profile&username=$ffname'>$ffname</a><br />"; }else{ echo "<a href='index.php?action=profile&username=$ftname'>$ftname</a><br />"; } ///end if } echo "</div>"; } ?> <br /> which is to pull that info, showing it on a users profile. but keep getting this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from='admin' LIMIT 0,10' at line 1 Any idea why? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/168561-solved-select-query-help/ Share on other sites More sharing options...
Philip Posted August 2, 2009 Share Posted August 2, 2009 from is a mysql reserved word, you need to either use backticks (`) around the column name, or ideally change the name of the column all together. Quote Link to comment https://forums.phpfreaks.com/topic/168561-solved-select-query-help/#findComment-889165 Share on other sites More sharing options...
adamlacombe Posted August 2, 2009 Author Share Posted August 2, 2009 Oh my.. I dont know why I didn't see that... I added `` to the other onces too lol. Quote Link to comment https://forums.phpfreaks.com/topic/168561-solved-select-query-help/#findComment-889166 Share on other sites More sharing options...
Philip Posted August 2, 2009 Share Posted August 2, 2009 This list should help http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html Quote Link to comment https://forums.phpfreaks.com/topic/168561-solved-select-query-help/#findComment-889168 Share on other sites More sharing options...
adamlacombe Posted August 2, 2009 Author Share Posted August 2, 2009 ok, Thanks Quote Link to comment https://forums.phpfreaks.com/topic/168561-solved-select-query-help/#findComment-889175 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.