Printing title to match group of photos. Help needed!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Printing title to match group of photos. Help needed!

Post by cturner »

I am trying to print a title and description to match a group of photos. I can't seem to work out how to do that. So can someone please have a look at my code and tell me how I should do this? Down the bottom of this post I have the way I am wanting the code to print. Thanks in advance.

My code:

Code: Select all

 
require "config.php";
// more code here
  $sql = "SELECT *
    FROM `livestock_photos`
    WHERE parent_id = '".mysql_real_escape_string($row['id'])."'";
  if($debug == TRUE)
    echo '<p>DEBUG3: '.$sql.'</p>';
  $result2 = mysql_query($sql)
    or die ('Could not query because: ' . mysql_error());
 
  while ($row2 = mysql_fetch_assoc($result2))
  {
     echo '<strong>'.$row2['title'].'</strong><br />';
     echo $row2['description']."<br />";
    echo '<a href="javascript&#058;void(0)" onClick="popWin(\''.$images_location_large.$row2['filename'].'.htm\', \'\', \''.$popup_width.'\', \''.$popup_height.'\')"><img src="'.$images_location.$row2['photos'].'" border="0" /></a> ';
    }
// more code here
 
This is the way I am wanting it to print:
Title1
Description1
Photo1 Photo2 Photo3

Title2
Description2
Photo1 Photo2 Photo3
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Printing title to match group of photos. Help needed!

Post by califdon »

And how is it printing now?
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Printing title to match group of photos. Help needed!

Post by cturner »

Title1
Description1
Photo1
Title1
Description1
Photo2
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Printing title to match group of photos. Help needed!

Post by califdon »

And how is the data structured in your table?
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Printing title to match group of photos. Help needed!

Post by cturner »

Livestock_photos's structure:
photos_id // auto-incremented number
parent_id // the listing's number from the livestock table
title
description
filename
photos
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Printing title to match group of photos. Help needed!

Post by califdon »

cturner wrote:Livestock_photos's structure:
photos_id // auto-incremented number
parent_id // the listing's number from the livestock table
title
description
filename
photos
"photos"? Plural? What is stored in the photos field of a typical record?

I'm not trying to string this out, but you aren't volunteering enough information for me to understand what you are working with. In order to answer your original question, "how to do this?", we can't just guess what you have or what you want to do.

If you have multiple photo URLs (or whatever?) in the same field of the same record, that is a very poorly designed database and you will have great difficulty retrieving data from it. The very first "normal form" of a relational database states that every column (field) must be "atomic", that is, the data cannot be divided into smaller parts. So if there is more than one piece of data in your "photos" field, I wouldn't even try to work with it.
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Printing title to match group of photos. Help needed!

Post by cturner »

What other information do you need then?

The table structure has been working for me. Photos has only one thing. The photos column holds the name of the photo with the file extension.
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Printing title to match group of photos. Help needed!

Post by cturner »

Come someone please help me. I am getting very desperate and need this to be finished asap.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Printing title to match group of photos. Help needed!

Post by califdon »

cturner wrote:What other information do you need then?

The table structure has been working for me. Photos has only one thing. The photos column holds the name of the photo with the file extension.
I will try to help you, but frankly, you're not helping yourself by the way you are describing your problem. Your field is named "photos", which led me to believe that you might be storing multiple photos, perhaps even image bitmaps in it. So now, if I can interpret your description of your data structure, it seems that you have something like this:

Code: Select all

 
[u]photos_ID  parent_ID  title           description             photos    [/u]
   101       38       Big Bang        This is an explosion    IMG0023.jpg
   102       38       Big Bang        This is an explosion    IMG0028.jpg
   103       41       Something       Another shot            IMG0186.jpg
   104       41       Something       Another shot            IMG0203.jpg
  .....
 
If that's representative of the data in your table (and apart from the fact that it's not a normalized table, with redundant data), you would have to use an awkward while loop and test for changes in parent_ID each time, to get the kind of display you want. That's why it's so hard to help people who begin with a flawed database structure. If that's NOT what your data looks like, again, you'll have to describe it. I'm out of guesses.
User avatar
cturner
Forum Contributor
Posts: 153
Joined: Sun Jul 16, 2006 3:03 am
Location: My computer

Re: Printing title to match group of photos. Help needed!

Post by cturner »

I believe I have explained my problem very clearly. Also I have no trouble displaying data from that table. As you haven't been very helpful I am going elsewhere to get this problem solved. Thanks for wasting my time.
Post Reply