473,396 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Cannot display multiple images per same id in one entry-Need some help

58
I need to dispaly a user's multiple images in one entry.Right now,say if a user uploads 3 images,three entries for the same id display to match 3 images.
I only want 1 entry to display all of a user's related images like below:
Id
First Name
Last Name
Title
Image1
Image2
Image3

Currently I get;
1
First Name
Last Name
Title
Image1

1
First Name
Last Name
Title
Image2

1
First Name
Last Name
Title
Image3

My select code is as follows:

[php]
include 'Con.inc.php';
$query = "SELECT Members.first_name,Members.last_name,Members.categ ory,Members.title,Members.message,Images.name,Imag es.type,Images.size,Images.path FROM Members LEFT JOIN Images ON Members.member_id=images.member_id";
$result = mysql_query($query);

while(list($first_name,$last_name,$category,$title ,$message,$file,$Type,$Size,$path)= mysql_fetch_row($result))
{
echo "first_name :$first_name <br>" .
"last_name :$last_name<br><br>".
"category :$category <br><br>".
"title :$title <br><br>".
"message:$message<br><br>".
"<img src='../FileDir/$path' alt='$first_name s profile photo' /><br>";
}

mysql_close($conn);
?>
[/php]

Thank you very much for your response in advance!
Nov 19 '07 #1
11 4131
MarkoKlacar
296 Expert 100+
Hi,

if you want the output you desire, you can't read/write all the information in one single loop. I'm guessing you need at least one more loop where you go though all the images that a user with the specific userid has linked to him/her.

Hope this helps.

Cheers
Nov 19 '07 #2
Jankie
58
Thank you MarkoKlacar,for your response !
I havent done this before so I have no clue how to add a conditioned second loop in my code above
Nov 19 '07 #3
MarkoKlacar
296 Expert 100+
Hi,

just to get an understanding of your database structure. The $path variable reads from the "Images.path" in the database. How is this connected to the user id?

As I see it, it's from .."Members.member_id=images.member_id", right?

Now what you could do is not select the images, but instead inside the while-loop you have execute one more query saying:

[PHP]$queryForMatching = "SELECT Images.part FROM Images WHERE Images.member_id = '$firstName'";[/PHP]

In the case above I'm assuming that the $firstName is the id used to map a user with his uploaded images.

After this you loop though the result that you receive and print out all the pictures.

Hope this helps.

Cheers
Nov 20 '07 #4
Jankie
58
thanks for your help

"As I see it, it's from .."Members.member_id=images.member_id", right?"

Yes.

member_id is what links a user to their images,not $firstname (I just missed it above)
Nov 21 '07 #5
MarkoKlacar
296 Expert 100+
Hi Jankie,

did you solve your problem, was I clear enough in my previous post?

Cheers
Nov 21 '07 #6
Jankie
58
Sorry for not updating you
Not yet really,do you mean a nested loop ?
If i understood you correctly,I have to delete the image selection info from the select statement(then I dont need the join statement,too) .Instead,I should include your query code inside the outer loop,correct ?
or how does your code fit in my code above ?
Sorry to sound dumb,didnt do it before
and thank you very much for your follow up ! Appreciate it.
Nov 21 '07 #7
MarkoKlacar
296 Expert 100+
Hi Jankie,

Yes I mean a nested loop. The nested loop goes through a new result array that was received from a new query where you select all the image.ids bellonging to a key that you're currently working with in the outer loop.

Hope I didn't confuse you with my mediocre description.

Let me know.
Nov 21 '07 #8
Jankie
58
MarkoKlacar
Thank you very much indeed
No,no your description is fine
yes,I got it to work with a nested loop inside the second query.
But I had to remove the join code along with image selection info from first query.

they are both linked now but just a where clause after I have stripped the table name part from the columns in the query.
[php]
"SELECT first_name,last_name,category,title,message FROM Members WERE member_id=member_id";
[/php]
[php]
"Select name,type,size,path FROM Images WERE member_id=member_id";

[/php]

I am just concerned the 2 tables are not now technically linked


Again,I do appreciate your staying with me,thanks a lot !
Nov 21 '07 #9
MarkoKlacar
296 Expert 100+
Hi Jankie,

they are linked using the primary keys, member id in this case.

Cheers
Nov 21 '07 #10
andho
34
I am just concerned the 2 tables are not now technically linked
it is technically linked from the php code right :D

and you dont need the WHERE clause in your first query now so they will be something like this:

Expand|Select|Wrap|Line Numbers
  1. $sql = "SELECT member_id, first_name,last_name,category,title,message FROM Members WERE member_id=member_id";
NOTE: that member_id is in the Select Column list.

now for the loop you should take the member_id like so:
Expand|Select|Wrap|Line Numbers
  1. while (list($member_id, $first_name, ....) {
and within the loop:

Expand|Select|Wrap|Line Numbers
  1. $sql = "Select name,type,size,path FROM Images WERE member_id=" . $member_id;
Nov 21 '07 #11
MarkoKlacar
296 Expert 100+
Hi,

sure a statement like that would be useless. But you have a table for storing users and you have a table for storing the images that a user has uploaded, right?

Even dough the id "is" the same the are the used as the primary keys in order to be able to match them.

So when execuring the nested query you need to store what user you are interested in and matching that one against the one in the images table.

By the way have you had any progress since last time?

Cheers
Nov 22 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: kingofkolt | last post by:
I have a directory of images, called "random". In it are the following files: 1.gif 2.gif 3.gif 4.gif I use this script to choose a random image and display it:
2
by: Mathias | last post by:
Dear NG, I currently ty to switch from matlab to python/scipy but have a lot of trouble with images. What I need is a function for subsequently displaying a number of 2D-matrices as an image. I...
3
by: ZZZupan | last post by:
http://www.naveur.navy.mil/default_test.asp I have tried with some success reorganizing the code and putting it all on one line. However for some reason I cannot get rid of the space on the last...
3
by: RAllsopp | last post by:
I have a client who would like to have several pictures associated with one system. I have read about storing only the pathname to save OLE overhead and have set-up a form for my client to...
12
by: Wadim Grasza | last post by:
I want to store and display (on a form or a report) multiple pictures per record in an access database. The pictures are not stored within the database. They are stored as files and the database...
26
by: Martin Jørgensen | last post by:
Hi, I don't understand these errors I get: g++ Persort.cpp Persort.cpp: In function 'int main()': Persort.cpp:43: error: name lookup of 'j' changed for new ISO 'for' scoping Persort.cpp:37:...
3
by: Dave | last post by:
I have an ASP 3.0 website on which the images are displaying intermittently. In other words, when I request a page, the image is blank. There is no missing image place marker (rectangle with a...
9
by: Confused but working on it | last post by:
Just wanted to say thanks for the posts helping me make ths work. Added a few comments and after the readdir used a pattern match to test for ..jpg, and seems to work fine on my test setup. Maybe I...
22
by: dfm | last post by:
Hi, I cant change the header to display images from a database. It's giving me this error : Warning: Cannot modify header information - headers already sent by (output started at...
0
by: javasachin | last post by:
Dear Friends, I have a requirement like this: In my JSP Page, I want to display some dynamic Arrow Images. While clicking on each of these Arrow Images, I want them to expand and create some...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.