...

View Full Version : help with this for pls



urgido
11-09-2010, 09:17 PM
I have problems with this code:


<?php
$tope=15;
for ($i=1; $i<=15; $i++){

if($i==15){
$COMITA="";
}else{
$COMITA=",\r\n";
}


if($rq['img'.$i.'']!=""){
echo '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
}
}
?>

I need to set empty $COMITA on my last cycle but I don't know why.
NOTE: My if condition is checking what field isn't empty on my db by this way the result can be variable.

Regards

Keleth
11-09-2010, 09:22 PM
And this is why indiscript variables suck. I'm not really sure what you're code is doing... echoing out something for javascript? Flash?

Whats wrong with it?

poyzn
11-09-2010, 09:23 PM
may be there is no $rq['img15'] ?

MattF
11-09-2010, 09:28 PM
Christ, that code is overly complex.



$count = 1;

while ($count <= 15)
{
if ($rq['img'.$count])
{
echo '["thumbmm.php?src=news/'.$rq['img'.$count].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]';
}
echo (($count++ != 15) ? "\r\n" : '');
}

Afro_Programmer
11-09-2010, 09:42 PM
I have problems with this code:


<?php
$tope=15;
for ($i=1; $i<=15; $i++){

if($i==15){
$COMITA="";
}else{
$COMITA=",\r\n";
}


if($rq['img'.$i.'']!=""){
echo '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
}
}
?>

I need to set empty $COMITA on my last cycle but I don't know why.
NOTE: My if condition is checking what field isn't empty on my db by this way the result can be variable.

Regards



<?php
for ($i=1; $i<=15; $i++){

if($rq['img'.$i.'']!=""){
echo '["thumbmm.php?src=news/'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]'.$COMITA;
}
}
unset($COMITA);
?>

urgido
11-10-2010, 12:10 AM
thanks all.

I solved this f* problem my self.


<?php
$tope=15;
for ($i=1; $i<=15; $i++){

if($i==15){
$COMITA="\r\n";
}else{
$COMITA=",\r\n";
}


if($rq['img'.$i.'']!=""){


$slideIM[]='["thumb.php?src=news'.$rq['img'.$i.''].'&h=340&w=380&zc=1", "", "", "SOME TITLE"]';

}
}

$ultimaIMG=end($slideIM);

foreach($slideIM as $imagenes){

if($ultimaIMG==$imagenes){
echo $imagenes."\r\n";
}else{
echo $imagenes.",\r\n";
}

}

?>


the goal my foreach LoL!

DrDOS
11-10-2010, 12:23 AM
Are you making a javascript array? Push is very simple to use for that, and also for PHP arrays, and you don't have to worry about removing the last comma.

urgido
11-10-2010, 12:37 AM
DrDos you're right, but I use jquery library that need to be removed my last comma. I don't know why.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum