Jump to content

is there a way to bring back school details once but all the images


deansaddigh

Recommended Posts

I have this code but because of the way it has been done i cant put the images above the description.

 

// select school details based on school id					
			 $query = "SELECT image_school.image_id, image_school.school_id, school.name AS school_name, school.street, school.town, school.city, school.county, school.region, school.school_facts, school.general_info, school.school_facilities, image.image_id, image.path, image.name AS image_name
            FROM image_school
            JOIN school
            ON image_school.school_id = school.school_id
            JOIN image
            ON image_school.image_id = image.image_id
		WHERE school.school_id =" .$school_id;

			$result = mysql_query($query, $conn)
               or die ("Unable to perform query: " . mysql_error());   

			$i = 0;

			while($row = mysql_fetch_array($result))
			{
				if($i == 0)
				{

					echo '<h2>'. $row['school_name'].' '. $row['town'] .'</h2><br />';



					echo '<p class=important> Location:'. $row['town'].'</p>';

					echo '<p class=important> County:'. $row['county'].'</p>';

					echo '<p class=important> Region:'. $row['region'].'</p>';

					echo '<div id="schooldetailbox">';
					echo '<p class="important">General Information :</p>';
					echo '<p>'. $row['general_info'].'</p>';
					echo '</div>';

					echo '<div id="schooldetailbox">';
					echo '<p class="important">School Facilities:</p><hr />';
					echo '<p>'. $row['school_facilities'].'</p>';
					echo '</div>';

					echo '<div id="schooldetailbox">';
					echo '<p class="important">School Facts :</p><hr />';
					echo '<p>'. $row['school_facts'].'</p>';
					echo '</div>';



					$i ++;
					echo "<div id='schoolimage'>";

				}

				$imagename = $row ['image_name'];
				 $image = 'Admin/'.$row['path'] . '/' . $row ['image_name'];
				echo '<img class="schoolimage" src="'.$image.'"/>';


			}					
			echo '</div>';

            ?>    

is there away in the sql query to bring back the school details only once but all the images

Link to comment
Share on other sites

No.  When you join 2 tables you get a row for every time the tables intersect.  So if that means that you have a school with 10 images, you're going to get 1 x 10 rows, where all that will be different is the columns you pull from images.  You also have the image_school table, but I don't understand how that table figures in, although relationally the rules are the same.

 

So you have 2 choices:

 

-Make your loop code more sophisticated, so that you only emit a new school markup when the school_id changes.  This is fairly standard and easy enough to do

-Inside your loop do a 2nd query for images for that school and fetch those seperately.

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.