roial Posted April 8, 2012 Share Posted April 8, 2012 hello i have built a webpage using tables. i might have done something wrong (except using tables) and now the results are rendered chaotically on the webpage. also here is the attached file. after the 4th article it's all messy i have a solution but that means to insert a php tag inside another php tag, but won't work thankyou 18007_.php Quote Link to comment https://forums.phpfreaks.com/topic/260557-3column-display-with-multiple-variables/ Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 Can we have some example output? My brain hurts from all the nested tables. Quote Link to comment https://forums.phpfreaks.com/topic/260557-3column-display-with-multiple-variables/#findComment-1335358 Share on other sites More sharing options...
roial Posted April 8, 2012 Author Share Posted April 8, 2012 the nested table solution was recommended by someone that, he say has great experience in php. (now i doubt) two day ago php was something i didn't know about and even if i cannot build a code by mysel i lerned that tables are outdated, so i made another file for the iteration (the final tabel to be repeated, in every cell of the parent table) i am attaching the tabple template file the result is right on pruduction page http://holidaystore.ro/hotels.php?Stati=Nisipurile%20de%20Aur meanwhile i am scouting the web for a logical solution and came up with this template as base start. <?php // Configuration Variables. $display_columns = 3; // Number of Columns. $display_format = "<td>".require_once("hotel_tmpl.php");."</td>"; // Format of Data $display_stable = "<table>\r\n"; // Format of Stating Table. $display_etable = "</table>\r\n"; // Format of Ending Table. $display_srow = "<tr>\r\n"; // Format of Starting Row. $display_erow = "</tr>\r\n"; // Format of Ending Row. // SQL and Prerequisites. $mysql_result = mysql_query("select * from hotel where statiune='$stati'"); $total_rows = mysql_num_rows($mysql_result); $offset = ceil( $total_rows / $display_columns ); $mysql_data = array(); // Logical Statements and Processing. while($mysql_return = mysql_fetch_array($mysql_result,MYSQL_NUM)) { $mysql_data[] = $mysql_return; } echo $display_stable; for ($i=0;$i<$offset; ) { echo $display_srow; for ($j=0;$j<$display_columns; ) { if (($j >= 0) && ($i + $offset*$j) < $total_rows) { $cust_id = $mysql_data[$i+$offset*$j][0]; $cust_name = $mysql_data[$i+$offset*$j][1]; $display = ereg_replace("%cust_id%",$cust_id,$display_format); $display = ereg_replace("%cust_name%",$cust_name,$display); echo $display; } $j++; } echo $display_erow; $i++; } echo $display_etable; ?> ---EDIT--- i didn't fully understant this generator code i found on the web. it is for listing costumer data in a table layout (i noticed it is kindof a table generator, right?) --- what's best? should i use the previous method or should i go for the generator ?? thanks for sharing your experience 18008_.php Quote Link to comment https://forums.phpfreaks.com/topic/260557-3column-display-with-multiple-variables/#findComment-1335365 Share on other sites More sharing options...
dcro2 Posted April 8, 2012 Share Posted April 8, 2012 The problem you're having is that you end the row (</tr>) in the third section of your while loop but never start another row, so the columns after the first three don't have their own row and the display is messed up. In any case, I think you should be doing something like this instead to not have to repeat your code three times: <tr> <?php $hotelsPerRow = 3; $i = 1; $qry_hotel = mysql_query("select * from hotel where statiune='$stati'"); while($hotel_rs=mysql_fetch_array($qry_hotel)) { ?> <td align="left" width="33%" valign="middle"> <table width="100%" border="0"> <tr> <td colspan="2" align="center"><img src="admincp/photos/hotel/<?php echo $hotel_rs['img1']; ?>" width="200" height="150"></td> </tr> <tr> <td width="118" height="28" align="right"> </td> <td width="80" align="center" valign="middle" background="imgs/prcbg.jpg" class="sidebar"><span class="style2"> <?php echo $hotel_rs['p_label']." "; ?> </span></td> </tr> <tr> <td colspan="2" align="left"><span class="tour"><a href="hotel.php?ID=<?=$hotel_rs['ID'];?>" class="tour"> <?php echo $hotel_rs['nume_hotel']; ?> </a></span></td> </tr> </table> </td> <?php if($i % $hotelsPerRow == 0) echo "</tr>\n<tr>"; $i++; } </tr> The modulus (%) operator checks the remainder when you divide by something, so when $i is divisible by $hotelsPerRow (when the remainder is zero), you start a new row. Also, try not to use the short php syntax (<? or <?=) because they're not recommended and if you change hosts they might not support it. Quote Link to comment https://forums.phpfreaks.com/topic/260557-3column-display-with-multiple-variables/#findComment-1335368 Share on other sites More sharing options...
roial Posted April 8, 2012 Author Share Posted April 8, 2012 your solution worked like a charm. thanks for your intervention. Quote Link to comment https://forums.phpfreaks.com/topic/260557-3column-display-with-multiple-variables/#findComment-1335387 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.