Jump to content

PHP Question, Im confused


perezf

Recommended Posts

What im trying to do is have the 1st and 3rd column have the same style,

but the 2nd one should have a different style.

 

I have 3 items per row,

how can i control it

 

This is what i have right now

<?php

for ($i=1;$i <= $numberofrows;$i++) {
$portitem = mysql_fetch_array($result);
if($portitem['imgsrc'] == NULL) {
	$imagesrc = '/portimages/defaultNULL.jpg';
} else {
	$imagesrc = '/portimages/' . $portitem['imgsrc'];
}
$takefirstpart = str_split($portitem['name'],5);
$therestofthetitle = substr($portitem['name'],5,1000);
if(strlen($portitem['domain'])>30) {
	$domaindisp = substr($portitem['domain'],0,30) . '...';
} else {
	$domaindisp = $portitem['domain'];
}
if($i%2) {
	print '<div class="sideones">';
	print '<div class="sideshead"><h1>' . '<span class="orangetxtcolor">' . $takefirstpart['0']  . '</span>' . $therestofthetitle . '</h1></div>';
	print '<div class="sidescontent">';
	print '<a href="http://www.' . $portitem['domain'] . '" title="Click Here to go to ' . $portitem['name'] . '\'s Website"><img src="' . $imagesrc . '" width="230" height="126" alt="' . $portitem['name'] . '" border="0" target="_blank" style="padding-bottom: 10px;" /><br /><span class="spanlink">www.' . $domaindisp .'</span></a>';
	print '</div>';
	print '</div>';
} else {
	print '<div class="middleone">';
	print '<div class="middlehead"><h1>' . '<span class="orangetxtcolor">' . $takefirstpart['0']  . '</span>' . $therestofthetitle . '</h1></div>';
	print '<div class="middlecontent">';
	print '<a href="http://www.' . $portitem['domain'] . '" title="Click Here to go to ' . $portitem['name'] . '\'s Website"><img src="' . $imagesrc . '" width="230" height="126" alt="' . $portitem['name'] . '" border="0" target="_blank" style="padding-bottom: 10px;" /><br /><span class="spanlink">www.' . $domaindisp .'</span></a>';
	print '</div>';
	print '</div>';
}
} ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/104976-php-question-im-confused/
Share on other sites

Maybe you need to check the remainder against something? Your code looks good to me. This is how I would do it. You've got some repeating code that you can eliminate too ;)

 

<?php
$c = 1;
while ($portitem = mysql_fetch_array($result))
{
$imagesrc = (empty($portitem['imgsrc']))
	? '/portimages/defaultNULL.jpg'
	: '/portimages/' . $portitem['imgsrc'];

$takefirstpart = str_split($portitem['name'], 5);
$therestofthetitle = substr($portitem['name'], 5, 1000);

$domaindisp = (strlen($portitem['domain']) > 30)
	? substr($portitem['domain'], 0, 30) . '...'
	: $portitem['domain'];

$class = ($c % 2 == 1) ? "side" : "middle";

print '<div class="{$class}ones">';
print '<div class="{$class}shead"><h1>' . '<span class="orangetxtcolor">' . $takefirstpart['0']  . '</span>' . $therestofthetitle . '</h1></div>';
print '<div class="{$class}content">';
print '<a href="http://www.' . $portitem['domain'] . '" title="Click Here to go to ' . $portitem['name'] . '\'s Website"><img src="' . $imagesrc . '" width="230" height="126" alt="' . $portitem['name'] . '" border="0" target="_blank" style="padding-bottom: 10px;" /><br /><span class="spanlink">www.' . $domaindisp .'</span></a>';
print '</div>';
print '</div>';
$c++;
}
?>

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.