Jump to content

3column display with multiple variables


roial

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.