Jump to content

PHP odbc for loop help!!


Merlin1

Recommended Posts

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!

Link to comment
Share on other sites

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!  :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.