Re: Javascript and php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, 7 Nov 2004 11:44:33 +0100, Reinhart Viane <rv@xxxxxxxx> wrote:

> Hope some of you also work on sundays :)
> 
> I have a little javascript which displays a images (with previous / next
> thing)
> Now, i populate the javascript array with an php array:
> 
> <SCRIPT LANGUAGE="JavaScript">
> 
> <!-- Begin
> NewImg = new Array (
> <?php
> while($row = mysql_fetch_object($result)){
> echo "\"".$row->picture_url."\",";
> }
> ?>
> "../pictures/7_stripper3.jpg",
> "../pictures/7_stripper2.jpg"
> );
> var ImgNum = 0;
> var ImgLength = NewImg.length - 1;
> ...
> </script>
> 
> As you can see i echo the url of the picture.
> After each picture url there needs to be a ','
> But not after the last picture.
> At this moment all pictures have the ',' after there url, even the last
> one.
> Any way to determine if the url is the url of the last picture and thus
> not printing a ',' behind that last one?
> 

Yes ... some work on sunday ;), at least to read the list

I took no much time to find out a solution for your problem, but a
possible question could be:

<?php
$list = array()
while($row = mysql_fetch_object($result)){
    $list[] = '"'. $row->picture_url .'"';
}
echo implode(',', $list);
}
?>

Another solution :

 <?php
$string = ''
while($row = mysql_fetch_object($result)){
  $string .= "\"".$row->picture_url."\",";
}
$string = substr($string, 0, strlen($string - 1);
?>

I have no tested the solutions, so could be some sintax error. But to
give you a couple of examples, hope that helps

Jordi

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux