Jump to content

About <div> in PHP, please help...


Hall of Famer

Recommended Posts

Well I have a code that looks like this:

 

<div style='width:100%; text-align:center; float:left;'>{$array[0][0]}</div>
<div style='width:50%; text-align:center; float:left;'>{$array[1][0]}</div>
<div style='width:25%; text-align:center; float:left;'>{$array[2][0]}</div>
<div style='width:12.5%; text-align:center; float:left;'>{$array[3][0]}</div>

 

As you can see, the width percentage decreases by half as the first index of $array increases by 1. I was wondering if its possible to write a PHP code such that the width percentage is automatically adjusted based on the first index of array. I've tried the following way as below, but it wouldnt work:

 

<div style='width:{100/(2^$i)}%; text-align:center; float:left;'>{$array[$i][$j]}</div>

 

So do anyone of you know how to do this? Please help.

Link to comment
https://forums.phpfreaks.com/topic/247918-about-in-php-please-help/
Share on other sites

umm looks like it wont work, I am assuming it is impossible to write an expression to specify the width percentage? The following code works perfectly:

 

<div style='width:25%; text-align:center; float:left;'>{$array[2][0]}</div>

 

But this one wont:

<div style='width:{(100/pow(2,2))}%; text-align:center; float:left;'>{$array[2][0]}</div>

Thank you so much, it works. And btw, can I resize images based on the same mechanism?

 

<img src='{$row['avatar']}' border=0 width='50' height='25' />

 

Can be converted into this?

 

<img src='{$row['avatar']}' border=0 width=".(100/pow(2,1))." height=".(100/pow(2,2))." />

I am assuming it is impossible to write an expression to specify the width percentage?

"expressions" inside strings only work if you start with a $ (like with a variable). There are creative ways around this though:

$expr = function($value) { return $value; }; // or use create_function()
$string = "{$expr(100/4)}%";

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.