473,396 Members | 2,030 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Use of PHP in Javascript

Hi,

I know it's not smart to use php and javascript together, but i need it. So I would like to know if this is possible.

This is my php code, I'm reading out my database.


[PHP]
<?php foreach ($listRows as $record): ?>
<?php $link1 = $record['link1'];
$link2 = $record['link2'] ;
$link3 = $record['link3'] ;
$link4 = $record['link5'] ;
$link5 = $record['link6'] ;
$link6 = $record['link7']; ?>

<?php endforeach ?>
[/PHP]

Now I need my $link vars in a javascript.
Is This possible??

This is my javascript.


Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. <!-- 
  3.  
  4.  stBM(2,"tree1d1a",[0,"","","blank.gif",0,"left","default","hand",0,0,-1,-1,-1,"none", 0,"#000000","transparent","","repeat",1,"defButton_f%20.gif","defButton_uf.gif", 9,9,1,"line_def0.gif","line_def1.gif","line_def2.gif","line_def3.gif",1,0,3,1,"center",0,0]);
  5. stBS("p0",[0,0]);
  6. stIT("p0i0",["Snel naar","","_self","","","defIcon_f.gif","defIcon_uf.gif",18,18,"9pt 'Arial'","#000000","none","transparent","","no-repeat","9pt 'Arial'","#000000","underline","transparent","","no-repeat","9pt 'Arial'","#FFFFFF","none","#000099","","no-repeat","9pt 'Arial'","#FFFFFF","underline","#000099","","no-repeat",0,0,"left","middle",0,0]);
  7. stBS("p1",[,1],"p0");
  8. stIT("p1i0",[$link1],"p0i0");
  9. stBS("p2",[],"p0");
  10. stIT("p2i0",["Netwerken",,,,,"defIcon_c.gif","defIcon_c.gif"],"p0i0");
  11. stIT("p2i1",["Servers"],"p2i0");
  12. stES();
  13. stIT("p1i1",[$link2],"p2i0");
  14. stIT("p1i2",[$link3],"p2i0");
  15. stIT("p1i3",[$link4],"p2i0");
  16. stIT("p1i4",[$link5],"p2i0");
  17. stIT("p1i5",[$link6],"p2i0");
  18. stES();
  19. stES();
  20. stEM();
  21. //-->
  22. </script>
  23.  
I use it to make a tree structure (like windows) but I want the topics to be the one's from my database.

$link obviously has to be replaced by the javascript var :)




Help would be very much appriciated
Feb 22 '08 #1
4 1644
Danigan
18
That's quite possible, but not in the way you're doing it. Keep in mind that PHP is all done with whatever it does by the time the code is sent to a web user. A user's machine can't see a PHP variable. JavaScript, however, is all sent to the user and all interpreted by the browser. Let me know if you have any questions on that part. Now for implementation...

Let's say you only have one variable to do. Let me know if you need more than this:

Expand|Select|Wrap|Line Numbers
  1. <?php $link2 = $record['link2'] ; ?>
  2.  
  3. <script language="javascript">
  4. stIT("p1i1",<?php echo '"' . $link2; . '"' ?>,"p2i0");
  5. </script>
  6.  
Now you have a whole insert of php code that echos the contents of the variable in $link2. When the webpage is sent to the user, the link is already a number, string, or whatever you had in it. Since it's the actual data from the variable on the user end (not a variable), you'll want quotes around it. I added that too. In php you concatenate with . if I remember right... sometime I confuse syntax like that since I program in a single language for a month or so and then switch. Hopefully this has helped, though. Let me know. :-)
Feb 22 '08 #2
That's quite possible, but not in the way you're doing it. Keep in mind that PHP is all done with whatever it does by the time the code is sent to a web user. A user's machine can't see a PHP variable. JavaScript, however, is all sent to the user and all interpreted by the browser. Let me know if you have any questions on that part. Now for implementation...

Let's say you only have one variable to do. Let me know if you need more than this:

Expand|Select|Wrap|Line Numbers
  1. <?php $link2 = $record['link2'] ; ?>
  2.  
  3. <script language="javascript">
  4. stIT("p1i1",<?php echo '"' . $link2; . '"' ?>,"p2i0");
  5. </script>
  6.  
Now you have a whole insert of php code that echos the contents of the variable in $link2. When the webpage is sent to the user, the link is already a number, string, or whatever you had in it. Since it's the actual data from the variable on the user end (not a variable), you'll want quotes around it. I added that too. In php you concatenate with . if I remember right... sometime I confuse syntax like that since I program in a single language for a month or so and then switch. Hopefully this has helped, though. Let me know. :-)


Thanks for your reply and your trouble.
I've tried it and now i get this


Expand|Select|Wrap|Line Numbers
  1. Parse error: syntax error, unexpected '.' in C:\hshome\oneideas\1id.be\testmenu.php on line 174
Feb 22 '08 #3
Danigan
18
I can't give more detailed help till this evening. What's the code on that line? (And the line before and after.) I'll look again in 8 to 10 hours.
Feb 22 '08 #4
I can't give more detailed help till this evening. What's the code on that line? (And the line before and after.) I'll look again in 8 to 10 hours.

Expand|Select|Wrap|Line Numbers
  1. stBS("p1",[,1],"p0");
  2. stIT("p1i0",<?php echo '"' . $link1; . '"' ?>,"p0i0");
  3. stBS("p2",[],"p0");
  4.  
Feb 22 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.