perezf Posted May 10, 2008 Share Posted May 10, 2008 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 More sharing options...
ondercsn Posted May 10, 2008 Share Posted May 10, 2008 if (is_int($i/2)) { ...codes for 2nd column } else { ...codes for 1st and 3rd columns Link to comment https://forums.phpfreaks.com/topic/104976-php-question-im-confused/#findComment-537539 Share on other sites More sharing options...
soycharliente Posted May 10, 2008 Share Posted May 10, 2008 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++; } ?> Link to comment https://forums.phpfreaks.com/topic/104976-php-question-im-confused/#findComment-537582 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.