Current location: Hot Scripts Forums » Programming Languages » PHP » Javascript Array In PHP


Javascript Array In PHP

Reply
  #1 (permalink)  
Old 11-12-09, 07:51 AM
deekshas deekshas is offline
New Member
 
Join Date: Nov 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Javascript Array In PHP

I want to create a single javascript array in PHP as shown in the code:
PHP Code:

<?

while($row=mysql_fetch_array($result))
                        {
                                        list(
$width$height$type$attr) = getimagesize($row[photoPath]);
                                        if((
$width 600) && ($height <= 900))
                                            {
                                                for (
$i$i<=1$i++)
                                                {
                                                    
                                                    echo 
"<a id=\"link\" href=\"$row[photoPath]\" rel=\"lightbox[roadtrip]\"><IMG src=\"$row[photoPath]\" WIDTH=\"300\" HEIGHT=\"400\"
                                                                 TITLE=\"Click to Enlarge\" id=\"but\" class=\"border\" /></a>"
;
                                                    echo 
"<br/><br/>";
//Value for javasript array row will come here
                    
                                                
}
                                                echo 
" <IMG src=\"$row[photoPath]\" WIDTH=\"75\" HEIGHT=\"75\"
                                                             TITLE=\"Click to Enlarge\" id=\"
$name\" class=\"border\"  onClick=\"change('$name')\"/> ";
                                                
$name $name 1;
                                                
$i $i+1;
                                                
                                                            
                                            }
                                        else
                                            {
                                                for (
$i$i<=1$i++)
                                                {
                                                    
                                                    echo 
"<a id=\"link\" href=\"$row[photoPath]\" rel=\"lightbox[roadtrip]\"><IMG src=\"$row[photoPath]\" WIDTH=\"600\" HEIGHT=\"400\"
                                                                 TITLE=\"Click to Enlarge\" id=\"but\" class=\"border\" /></a>"
;
                                                    echo 
"<br/><br/>";
                    
                                                }
                                                echo 
" <IMG src=\"$row[photoPath]\" WIDTH=\"75\" HEIGHT=\"75\"
                                                             TITLE=\"Click to Enlarge\" id=\"
$name\" class=\"border\"  onClick=\"change('$name')\"/> ";
                                                
$name $name 1;
                                                
$i $i+1;
//Value for javasript array row will come here
                                                            
                                            
}
                                        
                                    
                        }
                    echo(
"</td>");
                    echo(
"</tr>");
                    echo(
"<table>");


    
?>
Any help will be appreceated

Thanks,
Srinivas

Last edited by Nico; 11-12-09 at 08:36 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-12-09, 10:01 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
That's fairly easy.
Just echo some javascript creating an array with some PHP values as the array elements.
Example:
PHP Code:

<?php
$name 
= array("First name","Second name","Third name");
echo 
"<script>var myArray = new Array('".$name[0]."','".$name[1]."','".$name[2]."'); </script>";
?>
<script>
document.write(myArray);
</script>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks

Tags
php javascript


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Remove value from array Nikas PHP 1 05-20-09 04:20 AM
Multi-Dimensional Array Help Nikas PHP 17 05-04-09 03:10 AM
[SOLVED] Getting php vars to work in inline javascript problem med267 PHP 4 11-06-08 09:38 PM
For Hire (3 years exp.): Looking for Php, Mysql, AJAX, JavaScript, HTML, XML Barkat Job Offers & Assistance 1 09-25-07 05:15 PM
how to pass php array to javascript jaishalg PHP 2 12-23-05 04:28 AM


All times are GMT -5. The time now is 12:21 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.