Forum Moderators: coopster

Message Too Old, No Replies

Help with code

         

adammc

5:02 am on May 14, 2007 (gmt 0)

10+ Year Member



Hi guys,

Can anyone possible help me with this, I am really stuck.
The code I have shown below is spitting out image icons displayed in a table. It is currently allowing 2 cells each row then goes to a new 'tr'.

Can anyone see how I can change this to allow 3 or 4 results per table row?

[php]
<table width="100%" border=0 align=center cellpadding=0 cellspacing=0>
<tbody>
<tr valign=center>
<td height="25" colspan="2" align=center><h2 class="text6">Featured Employers</h2></td>
</tr>

<?php
$prm_emp_q=mysql_query("select * from sbjbs_premium_gallery where sb_approved='yes' ");
$num_rows=mysql_num_rows($prm_emp_q);
$max_allowed=$premium_cnt;

$number[0]=-1;
if($num_rows>$max_allowed)
{
for($i=0;$i<$max_allowed;$i++)
{
$unique=0;
while($unique==0)
{
$j=rand(0,$num_rows-1);
for($k=0;$k<count($number);$k++)
{
//echo $j;
if($number[$k]==$j)
break;
}
if($k>(count($number)-1))
{
$unique=1;
}
}
$number[$i]=$j;

}
}// end if num > no_allowed
/*for($k=0;$k<count($number);$k++)
{
echo $number[$k]." ";
}*/

$row=0;
$cnt=0;
$prm_emp=mysql_fetch_array($prm_emp_q);
while (($prm_emp)&&($cnt<$max_allowed))
{
$display=0;
if($num_rows>$max_allowed)
{
for($k=0;$k<count($number);$k++)
{
if($number[$k]==$row)
{
$display=1;
}
}
}
else
{
$display=1;
}
if($display==1)
{
$comp=mysql_fetch_array(mysql_query("select * from sbjbs_companies where
sb_id=".$prm_emp["sb_profile_id"]." and sb_approved='yes' and sb_show_profile='yes' "));

if($cnt%2==0)
{
?><tr valign=center><?php
}
?><td width="50%" align="center"><?php
if($comp["sb_show_profile"]=="yes")
{ echo "<a href='view_profile.php?id=".$comp["sb_id"]."'>";}
?><img src="uploadedimages/<?php echo $prm_emp["sb_img_url"];?>"
<?php echo $imgpmt;?> alt="<? echo $comp["sb_name"];?>" border="0"><?php
if($comp["sb_show_profile"]=="yes")
{ echo "</a>";}
?></td><?php
if($cnt%2==1)
{
?></tr><?php
}
$cnt++;
}//if display
$prm_emp=mysql_fetch_array($prm_emp_q);
$row++;
}// end while

?></tbody>
</table>

[/php]

There is a possibility that this setting isnt in this code.

I bought a script and have just learnt the hard way why you should just write your own instead of attmpting to wade through pages and pages of someone elses CRAPPY coding ;)

adammc

6:07 am on May 14, 2007 (gmt 0)

10+ Year Member



I have just been made aware that its the 'if($cnt%2==0)' part of the code thats causing this.

I still cant work out how to get it to create a new tr after every 4 results, instead of every 2 :(

Can anyone help?

adammc

6:52 am on May 14, 2007 (gmt 0)

10+ Year Member



Damn messy code!

I just ended up chopping out the "if($cnt%2==0)" and took the <tr> out of the while statement so I now have 4 images side by side.

Arno_Adams

6:59 am on May 14, 2007 (gmt 0)

10+ Year Member



Hi,

just replace '($cnt%2==1)'
with '($cnt%4==1)' AND '($cnt%2==1)' with '($cnt%4==1)'.

The percent operator is called modulus. It returns the remainder of $cnt divided by 4. If the remainder is 1 then a new row has to start. If there is no remainder (row is complete), the row has to end.

HTH, AA