/    Sign up×
Community /Pin to ProfileBookmark

for statment problem

Ok, on this site i’m working on i have values being grabbed from a database. I need them to be displayed 3 columns across then create a new row. there is also a caption that will go with each item so there will need to be two rows(one for the img and another for the caption) and it will need to span 3 columns across…here is what i have.

[code=php]
<?PHP
while($img = mysql_fetch_assoc($result))
{
?>
<tr>
<?PHP
for($i=”1″;$i<=”3″;$i++)
{
?>
<td width=”30%”>
<img src=”images/<?PHP echo $img[“name”]; ?>” />
</td>
<?PHP
} //end the for statment
?>
</tr>
<tr>
<?PHP
for($i=”1″;$i<=”3″;$i++)
{
?>
<td>
<?PHP echo nl2br($img[“caption”]); ?>
</td>
<?PHP
}//end the other for statment
?>
</tr>
<?PHP
}//end the while statement
?>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriNov 30.2004 — [code=php]
$num = 0;
while($img = mysql_fetch_assoc($result)) {
echo "<td width="30%">n<img src="images/".$img["name"]."" />n<br />".nl2br($row["caption"])."</td>";
if(is_int($num/3) && $num != 0) {
echo "</tr>n<tr>";
}
$num++;
}
[/code]
Copy linkTweet thisAlerts:
@Daniel_TNov 30.2004 — Just for the record, the problem with the for() statement in the first post was caused by the quotes around the numbers in the for() statement. When you put quotes around a value, PHP will interperate it as a string, instead of an integer. Since these numbers would then be treated as strings, you cannot use > or < to compare them. If you remove the quotes from within the for() statement, that should fix it. Although, I agree with Rich (96turnerri) that a while() statement would be more appropriate.
Copy linkTweet thisAlerts:
@GenixdeaeauthorNov 30.2004 — thanks, it works...and thanks for that info, it was usefull ?
Copy linkTweet thisAlerts:
@96turnerriDec 01.2004 — glad to help

the thing is you need to keep things as simple and as small as possible, i mean your 30line code and i rewrote to 8/9lines, i could make it less by loosing the if and making it a ternary expression.

i just coded a 104kb command file for a chat script i am making, and if i didnt keep things simple it would be a mess and hard to follow

but i guess that just comes with experience, just some wisdom i thought i would pass on ?

PS: DanielT - San Andreas, top game
×

Success!

Help @Genixdeae spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...