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!
11 4131
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
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
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
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)
Hi Jankie,
did you solve your problem, was I clear enough in my previous post?
Cheers
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.
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.
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 !
Hi Jankie,
they are linked using the primary keys, member id in this case.
Cheers
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: - $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: - while (list($member_id, $first_name, ....) {
and within the loop: - $sql = "Select name,type,size,path FROM Images WERE member_id=" . $member_id;
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
Sign in to post your reply or Sign up for a free account.
Similar topics
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:
|
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...
|
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...
|
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...
|
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...
|
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:...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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...
|
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...
|
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,...
| |