Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 923
Problem with a table while coding on PHP

I want to make a display of three cell lines. But the second line does not jump after three cells? Here is my code:
PHP Code:
<table> 
<tr style="margin:20px; border:1px solid red; padding: 20px;"> 
<?php 
$j 
1
foreach (
$result as $row

$id $row ['id']; 
$image $row ['image']; 
$name $row ['name']; 
$price $row ['price']; 
$description $row ['description']; 
stockMinimum $ = $row ['stockMinimum'];?> 
<td style = "border: 1px solid # fff; padding: 0px; position: relative; background-color: transparent; margin: 0px; text-align: center; width: 250px" > 
<h3 style="text-align:left; font-size:90%; margin:0 0 0 10px; padding:0;" > 
<?php echo nl2br ($ model-> debutTexte ($ name18 ));? > 
</
h3
<
span style="font-weight: bold; margin:0 0 0 110px;" 
<?
php echo $ price;?> &nbsp;&euro;
</span> 
<p> <?php 
$tabImage 
explode '', $ image); 
if (isset (
$tabImage [0]) &&! empty ($tabImage [0])) 
{
echo 

<a href = "?page=detailProduct&amp; idProduct = '
.$id.'&amp; category = '.$idCategory.'" >

<img src = "http://forums.techarena.in/images/'
.$tabImage[0].
style = "
border3px solid # fff; height: 140px; width: 140px;" alt = "product $tabImage[0]" /> 
</a>'; 

else 
echo '
<img src="img/noImage.jpg" style="height:90px; width:90px;" alt="Aucune image description" />';?
</p> 
<p> 
<span style="display:block;"> 
<?php echo html_entity_decode (nl2br ($model -> debutTexte ($description,17)));?> 
</span> 
<span style="display:block;"> 
<a href="?page=detailProduct&amp; idProduct=<?php echo $id;?>&amp; category=<?php echo $idCategory;?>">
see description 
</a> 
</span> 
</p> 
</td> <?php 
if ($ j%6 == 3) echo '
</ tr><tr>'; 
$ j++; 

}?> 
</tr></table>
Reply With Quote
  #2  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 804
Re: Problem with a table while coding on PHP

I don't know much about PHP but in my opinion there should be some problem in the below code:

PHP Code:
if ($ j%== 3) echo '</tr><tr>;  
$ j++; 
Reply With Quote
  #3  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 1,304
Re: Problem with a table while coding on PHP

Yes Baltazar, you are right. It should be

PHP Code:
if ($ j== 0) echo '</tr> <tr>'
j++; 
With your below code:

PHP Code:
if ($ j== 3) echo '</ tr> <tr>'
j = 1, 2 and 3: 3% 6 ==> 3 / 6 = 0 remainder 3. So it works.
But j = 6: 6% 6 ==> 6 / 6 = 1 is 0, it does more. Therefore, when on the second line, it does not jumps.

It is useless to have % 6 while you want a % 3!
__________________
Broadband Unlimited Plans
Reply With Quote
  #4  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 923
Re: Problem with a table while coding on PHP

Thanks for your responses. But I am confused between j%3 == 0 and j/3 = 0? Are they one and the same?
Reply With Quote
  #5  
Old 12-11-2008
Member
 
Join Date: May 2008
Posts: 1,304
Re: Problem with a table while coding on PHP

The mod returns the below result:

1 % 3 = 1 - (3 * 0) = 1
2 % 3 = 2 - (3 * 0) = 2
3 % 3 = 3 - (3 * 1) = 0
4 % 3 = 4 - (3 * 1) = 1
5 % 3 = 5 - (3 * 1) = 2
6 % 3 = 6 - (3 * 2) = 0

Therefore, test $ j % 3 == 0 => 3 equals 0 <=> $ j is a multiple of 3.
__________________
Broadband Unlimited Plans
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Problem with a table while coding on PHP"
Thread Thread Starter Forum Replies Last Post
Link a Table to another Table to Drop Down In Main Table himeshRES Windows Software 6 11-12-2010 02:01 PM
Hyper-V Cluster, ARP table problem warehouse peon Operating Systems 5 07-04-2010 01:09 AM
Writing temporary table problem Jabeena Software Development 4 13-02-2010 12:20 PM
Problem with MBR and allocation table JUSTICE Operating Systems 3 25-02-2009 11:27 PM
Problem with C coding SANDESH49 Software Development 2 02-09-2008 01:23 PM


All times are GMT +5.5. The time now is 06:13 AM.