Merlin1 Posted July 3, 2008 Share Posted July 3, 2008 Hey. Im working on a social networking site at the moment and im using Access database and connecting to it via odbc. The problem i have is that a users friends are stored in a text file and i need to pull all of that users friends out from the database and display their username and image. Here is my code <table cellpadding='0' cellspacing='0' width='100%'> <td valign='middle' class='subHead'>Friends ( ) - View All</td> <tr> <td class='subContent'><br /> <?php $userName = odbc_result($users_rs,'Username'); $friends = file('../'.$userName.'/friends/friends.txt'); $friendCount = count($friends); echo'<table width="100%">'; for ($f = 0;$f<count($friendCount);$f++){ $fs = odbc_exec($conn,"SELECT * FROM Users WHERE Email='".$friends[$f]."'"); echo '<td class="friendBox0">'; echo '<a href="../'.odbc_result($fs,'Username').'"><img border="0" src="'.odbc_result($fs,'thumbPicture').'" /></a></td><td class="friendBox"><a href="../'.odbc_result($fs,'Username').'">'; echo odbc_result($fs,'Name'); echo '</a></td><tr>'; if($f == 6){ break; } } echo'</table>'; ?> </td> </table> The problem is, it only works when there is one user in the text file, if theres more nothing comes up. Could this be because i am re-using the variable that excecutes the SQL? or am i missing something completly? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
Barand Posted July 3, 2008 Share Posted July 3, 2008 methinks this for ($f = 0;$f<count($friendCount);$f++){ should be for ($f = 0;$f<$friendCount;$f++){ Quote Link to comment Share on other sites More sharing options...
TransmogriBenno Posted July 3, 2008 Share Posted July 3, 2008 Not related to the issue, but, for performance reasons, you should store the friends list in the database too. On the same note, you should use something other than Access to look after your database. Quote Link to comment Share on other sites More sharing options...
Merlin1 Posted July 4, 2008 Author Share Posted July 4, 2008 methinks this for ($f = 0;$f<count($friendCount);$f++){ should be for ($f = 0;$f<$friendCount;$f++){ Oh my god! of course it should be lol, thank you very muhc for pointing that out! Works fine now! Quote Link to comment Share on other sites More sharing options...
Merlin1 Posted July 4, 2008 Author Share Posted July 4, 2008 Ok no it didnt work... i have no idea why i cant pull out different records with a for loop.. its only pulling out the last iteration. Quote Link to comment Share on other sites More sharing options...
Barand Posted July 4, 2008 Share Posted July 4, 2008 I expect all but the last have "\n" at the end of the line. Trim $friends[$f] before using in the query. Quote Link to comment Share on other sites More sharing options...
Merlin1 Posted July 4, 2008 Author Share Posted July 4, 2008 Ah yes thank you very much it actually does work now!!! ive been pulling my hair out over this for ages.. thanks very much! 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.