By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,642 Members | 1,672 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,642 IT Pros & Developers. It's quick & easy.

Easy if....question

P: n/a
Eze
Hi!!!!

I need to create a table of 4 columns x n rows. The number of row will
depend on the number of images for that specific page.

I think that I have to use de mod function saying that if (number of
image mod 4 equal 0 then start another row)

Well....first thing...I find the function fmod in the help that I
think that will be useful.

I wrote this small code, but it does not work

while($row = mysql_fetch_array($respuesta))
{
echo('<td width=15% align="center"><img src=" ' .$row["url"]. '
"></td>');
$i++;
if (fmod ($i,4)==0)
{
<tr>
}
}

Anyone can help me?

Thanks in advance

Ezequiel
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
In article <e1**************************@posting.google.com >,
es*******@hotmail.com (Eze) wrote:
I think that I have to use de mod function saying that if (number of
image mod 4 equal 0 then start another row)


It seems simpler to me to just check if the number is equal to 4, and if
it is, reset it to zero again.

$i = 0;
while($row = mysql_fetch_array($respuesta)) {
if ($i < 4) {
do_something();
$i++;
} elseif ($i == 4) {
do_something_else();
$i = 0;
}
}

JP

--
Sorry, <de*****@cauce.org> is een "spam trap".
E-mail adres is <jpk"at"akamail.com>, waarbij "at" = @.
Jul 17 '05 #2

P: n/a

On 17-Apr-2004, es*******@hotmail.com (Eze) wrote:
I need to create a table of 4 columns x n rows. The number of row will
depend on the number of images for that specific page.

I think that I have to use de mod function saying that if (number of
image mod 4 equal 0 then start another row)

Well....first thing...I find the function fmod in the help that I
think that will be useful.

I wrote this small code, but it does not work

while($row = mysql_fetch_array($respuesta))
{
echo('<td width=15% align="center"><img src=" ' .$row["url"]. '
"></td>');
$i++;
if (fmod ($i,4)==0)
{
<tr>
}
}

Anyone can help me?


You have several problems. The fmod() or % will work, I find counting
easier. Your HTML is wrong (spaces in the src= parm for example). The <tr>
in the if needs an echo or something.

This should be close (untested):

echo '<table>';
$i = 0;
while($row = mysql_fetch_array($respuesta))
{
if ($i==4)
{
echo '</tr><tr>';
$i=0;
}
echo '<td width="15%" align="center"><img src="' .$row["url"]. '"></td>';
$i++;
}
while($i<4)
{
echo '<td> </td>';
$i++;
}
echo '</tr></table>';
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #3

P: n/a
In message <7g******************@newssvr27.news.prodigy.com >, Tom
Thackrey <us***********@nospam.com> writes
You have several problems. The fmod() or % will work, I find counting
easier. Your HTML is wrong (spaces in the src= parm for example). The
<tr> in the if needs an echo or something.

This should be close (untested):

echo '<table>';
echo '<tr>';
$i = 0;
while($row = mysql_fetch_array($respuesta))
{
if ($i==4)
{
echo '</tr><tr>';
$i=0;
}
echo '<td width="15%" align="center"><img src="' .$row["url"].
'"></td>';
$i++;
}
while($i<4)
{
echo '<td> </td>';
$i++;
}
echo '</tr></table>';


--
Five Cats
Email to: cats_spam at uk2 dot net
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.