Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning rows one by one 1

Status
Not open for further replies.

DaSe

Programmer
Feb 14, 2008
149
GB
Hi guys...
I have something to ask you if you don't mind. A bit of explanation: I have a table with 'friend_id' field and 2 other fields which stores an added user id. This added user id I am trying to match with users id of the 'members' FOLDER into which user keep their jpg photos. It's pretty difficult to me and I came up with this way: I am being returned a row from friend_id and this id I try to match with directory of the members folder. But the problem is that when I use concatenation it returns all ids in one go without any split. Something like: 20293190139 whereas what I need to is: 202 then 931 then 19 etc. I really don't know what would be the best way of doing it ? I mean matching users pics to their ids from the table. Regards.

 
Code we need to see your code.

But the problem is that when I use concatenation it returns all ids in one go without any split. Something like: 20293190139 whereas what I need to is: 202 then 931 then 19 etc.

Well if its returning it together, that's probably because that's the way you are outputting it. But before we can help we need to know what you are doing.








----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi Phil..sure..I'll try to be concise..

I've got a folder 'members' in which you have subfolders of the new users' accounts in which they store their jpg photos:

Code:
$dir = "members/$id/userImg1.jpg";

Then I have a separate table that has 3 fields: uid, friend_id , user_id. This table stores added users ids from a link when you press 'add user'. What I do is this:

Code:
$sql_members_add = mysql_query("SELECT `friend_id` FROM `members` WHERE `user_id`='$uid' ORDER BY `user_id` DESC ");

while ($rows = mysql_fetch_array($sql_members_add)) { 
$f_id = $rows['friend_id'];

}

$friends = $f_id;

$mem_dir_add = "members/".$friends."/userImg1.jpg";

$array_pic = "<img src='$mem_dir_add' width='40' height='60' border='1' align='left'/>";

As you can see there's no concatenation in while loop. And it returns only first id. This id is matched in $mem_dir_add and that's fine. If I add concatenation it will return all the ids in one go and they won't match the folder.

 
Just so I'm sure I understand:
What you want is to get is as many pictures as you get results? Where each picture gets a different path depending on the f_id you get back. So in your example, you'd want to have 3 pictures with paths that use the f_id's 202 then 931 then 19 etc...

Is that it?




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Absolutely right. This is what I need. The pictures will be next to each other on "Added users" page. The pictures will be made as links ( the thing I have no problems about ) but I have problems how to display them as you said according to their ids from the table.

 
The easiest way would be to include your image portions in the while loop of your DB request, and either concatenate the resulting image tags or just make them into an array.

Code:
$sql_members_add = mysql_query("SELECT `friend_id` FROM `members` WHERE `user_id`='$uid' ORDER BY `user_id` DESC ");

while ($rows = mysql_fetch_array($sql_members_add)) {
  $friends = $rows['friend_id'];

  $mem_dir_add = "members/".$friends."/userImg1.jpg";

  $array_pic[blue][][/blue] = "<img src='$mem_dir_add' width='40' height='60' border='1' align='left'/>";
[COLOR=yellow red]}[/color]

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Aha...Phil you're PHP-Almighty. I'll try to play with this in a moment and see...Thanks so much.

 
That works absolutely fine...so that was the issue of putting it into while loop .Just need to modify a bit few things. Thank you Phil.

 
Of course ! I just fell almost asleep that day. Sorry for omission.

 
It was supposed to be vacunita (AKA Phil) that you gave the star to!

If you want the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top