php - How to add align (left, center, right) to table inside a loop -


how add align table loop?

i have code:

<table width="960px" border="0" cellspacing="0" cellpadding="0">   <tr valign=top>   <? activate ('main/inside'); $rid = ('main/inside'); $l = openfileslist (page, 'id', asc, 20); $i = 0; while ($id = readlist ($l)) { setactive ($id); if (!$rid) $rid = _say ('Раздел'); $q = 0; $arr = array('left', 'center', 'right'); if ($i == 0) echo '<td align='.$arr[$q++].'>';     ?> "some text" <?  if ($i++ == 1) {         echo '</td>';         $i = 0;     } } if ($i>0) {      echo str_repeat ('', 2-$i);     echo ''; }  ?>  </tr>     </table> 

the output should

... <td align="left">some text text</td> <td align="center">some text text</td> <td align="right">some text text</td>... 

but code not work properly.

change

if ($i == 0) echo '<td align='.$arr[$q++].'>'; 

to

if (!$i) echo '<td style="text-align:'.$arr[$q++].';">'; 

it when use css instead of old html. more text align here:

http://www.w3schools.com/cssref/pr_text_text-align.asp

also remember $arr[$q++] can have values: left, right, center, justify , inherit. no other value accepted.

the thing want may done without php can done via js or css. example if put in

you can use css3 code

 table.mytable tdp:nth-child(1){text-align:left;}  table.mytable tdp:nth-child(2){text-align:center;}  table.mytable tdp:nth-child(3){text-align:right;} 

it make first column align left, second column center , third column right.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -