son Posted May 4, 2011 Share Posted May 4, 2011 I retrieve data from two tables and get the individual data with a join. As one field of the joined table holds redundant data (it is the section the relevant images are in) I would like to disply this field only once as a heading. Is there a way to do this with the join query I am using? I hold the data for each images as $imgPage = $row['page'];. Could I somehow compare it, so that when the value changes then I display a new heading or similar? I would like to avoid to wrap a query around to run through sections separately...Thanks,Son Link to comment Share on other sites More sharing options...
birbal Posted May 4, 2011 Share Posted May 4, 2011 I am not sure about the problem...can you paste the codes? Link to comment Share on other sites More sharing options...
son Posted May 4, 2011 Author Share Posted May 4, 2011 I am not sure about the problem...can you paste the codes?The code is:$thumbDisplayQuery = "SELECT gallery.imgID, gallery.img1, galleryCat.page FROM gallery, galleryCat WHERE gallery.imgCat = galleryCat.pageId ORDER BY imgCat";$thumbDisplayResult = mysqli_query ($dbc, $thumbDisplayQuery);while ($row = mysqli_fetch_array ($thumbDisplayResult, MYSQL_ASSOC)) { $imgID = $row['imgID']; $img = $row['img1']; $imgPage = $row['page']; $size = getimagesize("../gallery/thumb/{$img}"); echo "<div><h2>" . $imgPage . ": " . $imgSortNr . "</h2><a href=\"gallery.php?imgID=" . $imgID . "\" title=\"Delete\"><img src=\"" . $imgPreviewPath . "/" . $img . "\" " . $size[3] . " alt=\"Delete\" /></a></div>\n"; } Instead of echo "<div><h2>" . $imgPage . ": " . $imgSortNr . "</h2><a href=\"gallery.php?imgID=" . $imgID . "\" title=\"Delete\"><img src=\"" . $imgPreviewPath . "/" . $img . "\" " . $size[3] . " alt=\"Delete\" /></a></div>\n"; I would like something as: echo "<h2>" . $imgPage . "</h2>"; // only once to display a heading for all images that share the same page; after this only display relevant divs until an image is retrieved that has a different heading; then display the new heading againecho "<div><a href=\"gallery.php?imgID=" . $imgID . "\" title=\"Delete\"><img src=\"" . $imgPreviewPath . "/" . $img . "\" " . $size[3] . " alt=\"Delete\" /></a></div>\n"; Hope this makes it more clear...Son Link to comment Share on other sites More sharing options...
birbal Posted May 4, 2011 Share Posted May 4, 2011 there may be better way but thats what coming in my mind now..something like this should work..you need to order by imaepage in the query $pagePrev='';while(...){ if($row['imagePage']!=$pagePrev) { $heading="<h2>{$row['imagePage']}</h2>"; $pagePrev=$row['imagePage']; } else $heading='';echo $heading;echo "<div><a href=\"gallery.php?...........";} Link to comment Share on other sites More sharing options...
son Posted May 4, 2011 Author Share Posted May 4, 2011 there may be better way but thats what coming in my mind now..something like this should work..you need to order by imaepage in the query$pagePrev='';while(...){ if($row['imagePage']!=$pagePrev) { $heading="<h2>{$row['imagePage']}</h2>"; $pagePrev=$row['imagePage']; } else $heading='';echo $heading;echo "<div><a href=\"gallery.php?...........";} Hi birbal,That is cool. Cheers, exactly what I was after. I did try something similar, only that I did not think right and had my equivalent to $pagePrev=''; inside the loop|-)Thanks,Son Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.