shawhey Posted May 26, 2011 Share Posted May 26, 2011 I'm not sure if this would be considered a math question, but I wasn't sure where to post it. Before I start, here's a link to the page: http://ezliquidators.1free.ws/products.php?mat=granite I'm trying to create a header for each of the different sizes of tiles if the user doesn't specify a size. This is difficult, because if I just put it in the array, it will create a header for each individual tile as opposed to creating one for each unique size. Any ideas? I'm at a loss for anything that could work right now. Here's the PHP: <?php $mat = $_GET['mat']; $size = $_GET['size']; $count = -1; if ($size >= 1) { $sql = mysql_query("SELECT * FROM Products WHERE Type = '".$mat."' AND Size = '".$size."' "); } else { $sql = mysql_query("SELECT * FROM Products WHERE Type = '".$mat."' "); } while ($r = mysql_fetch_array($sql)) { $count++; if ($newrow==$count%4) { ?> </tr><tr> <?php } ?> <td> <a href="<?php echo $r[image]; ?>" rel="lightbox" title="<?php echo $r[Name]; ?>"><img id="tile" src="<?php echo$r[image]; ?>"></a> <br> <p id="tileinfo"> <?php echo "$r[Name] ($r[Dimensions])"; } ?> Cheers, Chahe Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/ Share on other sites More sharing options...
btherl Posted May 26, 2011 Share Posted May 26, 2011 You can have your script remember the size of the last tile, and only print a header when the size changes, or if it's the first tile. I assume you would want to order the results by size as well in your SQL. Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/#findComment-1220424 Share on other sites More sharing options...
shawhey Posted May 26, 2011 Author Share Posted May 26, 2011 Yes, that's right. I know how to sort by size, but how would I write the script to remember the size of the last tile? Also, if it's remembering the last tile, wouldn't that mean it would put the header in one tile too late? Since it wouldn't realize the size had changed until after a new one comes out. Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/#findComment-1220598 Share on other sites More sharing options...
btherl Posted May 26, 2011 Share Posted May 26, 2011 It would look like this: $last_tile_size = null; while ($r = mysql_fetch_array($sql)) { # New code if ($last_tile_size === null || $last_tile_size != $r['Size']) { echo "<h4>Welcome to tile size {$r['Size']}!</h4>"; } $last_tile_size = $r['Size']; # Existing code goes here } This will print a header before the data for the first tile (which is why it checks for null), and for any tile where the previous tile was a different size. Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/#findComment-1220886 Share on other sites More sharing options...
shawhey Posted May 27, 2011 Author Share Posted May 27, 2011 Cheers for the help. I figured it out last night with a slightly different approach. if ($r[size]>$prevsize) { ?> </table> <h3 id="dimension"><?php echo $r[Dimensions]; ?> </h3> <table> <?php } $prevsize = $r[size]; I have a new problem now that the active link in the sidebar doesn't change since it's all on one page that just refreshes with different values to the mat and size variables. I'm assuming all I'll need to do on the html end is add a body id that equals those variables, but I haven't quite figured out the css end of it. Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/#findComment-1221328 Share on other sites More sharing options...
shawhey Posted May 27, 2011 Author Share Posted May 27, 2011 Nevermind, got it. Quote Link to comment https://forums.phpfreaks.com/topic/237500-need-multiple-headers-from-one-query/#findComment-1221378 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.