Page 1 of 1

Printing title to match group of photos. Help needed!

Posted: Sun Jul 06, 2008 3:29 pm
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

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

Posted: Sun Jul 06, 2008 3:38 pm
by califdon
And how is it printing now?

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

Posted: Sun Jul 06, 2008 3:40 pm
by cturner
Title1
Description1
Photo1
Title1
Description1
Photo2

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

Posted: Sun Jul 06, 2008 7:18 pm
by califdon
And how is the data structured in your table?

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

Posted: Sun Jul 06, 2008 7:34 pm
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

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

Posted: Sun Jul 06, 2008 8:19 pm
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.

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

Posted: Sun Jul 06, 2008 9:00 pm
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.

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

Posted: Mon Jul 07, 2008 12:46 am
by cturner
Come someone please help me. I am getting very desperate and need this to be finished asap.

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

Posted: Mon Jul 07, 2008 2:59 pm
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.

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

Posted: Mon Jul 07, 2008 4:23 pm
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.