[solved][56K WARN] php and javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

[solved][56K WARN] php and javascript

Post by dharprog »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi

I would like to know one thing that how to work out the php code snippets in javascript? 

Suppose i have javascript like this 

[syntax="html"]<script type="text/javascript">
<!-- TreeView Demo 3 //-->
var palmtree=new jktreeview("tree3")
palmtree.addItem("Coding Forums", "", "http://www.codingforums.com")
palmtree.addItem("PHP Reference", "", "http://www.php.net")
palmtree.addItem("Mozilla Dev Center", "", "http://developer.mozilla.org/en/docs/Main_Page")
var branch4=palmtree.addItem("CSS Drive") //A TREE BRANCH WITH NO URL FOR ITSELF
here i would like to add the php code but not working when i add this code[/syntax]

Code: Select all

<?php $sr = get_result1("sub_cat",cat_name,"Love Hearts");  while($rr = mysql_fetch_array($sr)){
echo "palmtree.addItem('".$rr['s_cat_name']."', branch4, 'http://www.cssdrive.com')"; }  ?>
[/color]

Code: Select all

	palmtree.addItem("CSS Gallery", branch4, "http://www.cssdrive.com") //Add this item to branch4
	palmtree.addItem("Web Design News", branch4, "http://www.cssdrive.com/index.php/news/") //Add this item to branch3
	palmtree.addItem("CSS Compressor", branch4, "http://www.cssdrive.com/index.php/main/csscompressor/") //Add this item to branch3
palmtree.addItem("Ajaxian", "", "http://ajaxian.com/")
palmtree.treetop.draw(); //REQUIRED LINE: Initalize tree
</script>
So please how can i make it work. Please help me out.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

[quote="[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1"][b]2.[/b] Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.[/quote]
Last edited by dharprog on Tue May 29, 2007 7:06 am, edited 2 times in total.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

here i would like to add the php code but not working when i add this code
Please explain.

What is cat_name in the following code? Are you passing this as a string?

Code: Select all

get_result1("sub_cat",cat_name,"Love Hearts");
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Why are you echoing <BR>? You're generating JavaScript, not HTML.

And why echo </script> inside of PHP? That doesn't make sense to me, especially doing so within a loop. You may end up doing it more than once.


Have you looked at the source generated from your PHP?
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

Hi

I just edited the message above. In that thats a javascript totally but php code inserted in between the javascript.

In which that is printing/echoing the statements but out of the body or behind javascript sentences. And

In that cat_name is a variable passing.

Thank YOu.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

dharprog wrote:In that cat_name is a variable passing.
Did you forget your "$"?
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

superdezign wrote:
dharprog wrote:In that cat_name is a variable passing.
Did you forget your "$"?

Hi No thats a direct string no need to have "$". I didnt forget about that. Php code is perfect in which in php page thats giving the correct results.

My problem is Thats not coming down to that above javascript code . I mean that results not placing between the javascript code like "palmtree.addItem("CSS Gallery", branch4, "http://www.cssdrive.com")";

So for that what i have to do.

Please tell me is there any tutorials for embedding php in javascript in a right way.

Thank you very much.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

It's as simple as echoing it, like you're doing. Nothing complicated.

Post the source that results from that snippet of PHP code, so you know what's going wrong.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

hI

Here is the image which i'm getting.

Image

The out put of the php code is :

palmtree.addItem('love134d', branch4, 'http://www.cssdrive.com')
palmtree.addItem('Heart', branch4, 'http://www.cssdrive.com')


Those are directly priting of the php code out put on right top side (Two lines). Those two lines should come between the javascript code then the fucntion will work.

WHen they clearly place in between javascript then i get the correct output like left hand side like under CSS Drive i get these two "love134d" and "heart" including with CSS Gallery, web desing news and so on...

Thank you.

Thank you.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

Hi

If it works perfectly then i get the output like this.

Image

Thank you.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Can you show me that page's HTML source code?

Edit: Never mind. You fixed it, I see.
Edit: Or not.. I misread your post.
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi

I didnt get the solution. I just added manually those 2 things to show you the output without getting through php code.


Here is the php page code (I mean which you have asked for the html code)

Code: Select all

<?php
session_start();
include 'admin/conn.php';
include 'admin/functions.php';?>

<!doctype html public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Tree View</title>
<link rel="stylesheet" type="text/css" href="css/multi/tree.css">
<script type="text/javascript" src="build/yahoo.js" ></script>
<script type="text/javascript" src="build/event.js"></script>
<script type="text/javascript" src="build/treeview.js" ></script>
<script type="text/javascript" src="build/jktreeview.js" ></script>


<!-- Below is Style sheet for demos. Removed if desired -->
<style type="text/css">

body {font: normal 11px verdana, sans-serif; color: #333; line-height: 19px;}
a { text-decoration: underline; color: #46546C; }
a:hover { text-decoration: underline; color: #4d77c3; }
#tree1 {width:250px;padding: 10px;float:left;}
#tree2 {width:250px;padding: 10px;float:left;}
#tree3 {width:250px;padding: 10px;float:left;}

</style>

</head>

<body>

<h2>Folding TreeView Menu demo: <a href="http://www.javascriptkit.com/script/treeview/">More info</a></h2>

<!--Empty DIV tags to contain the treeview demos -->
<div id="tree3" class="treemenu"></div>


<script type="text/javascript">
<!-- TreeView Demo 3 //-->
var palmtree=new jktreeview("tree3")
palmtree.addItem("Coding Forums", "", "http://www.codingforums.com")
palmtree.addItem("PHP Reference", "", "http://www.php.net")
palmtree.addItem("Mozilla Dev Center", "", "http://developer.mozilla.org/en/docs/Main_Page")
var branch4=palmtree.addItem("CSS Drive") //A TREE BRANCH WITH NO URL FOR ITSELF
</script>
<?php $sr = get_result1("sub_cat",cat_name,"Love Hearts");  while($rr = mysql_fetch_array($sr)){ 
echo "palmtree.addItem('".$rr['s_cat_name']."', branch4, 'http://www.cssdrive.com')"; }  ?>
<script type="text/javascript">
    palmtree.addItem("love134d", branch4, "http://www.cssdrive.com")
	palmtree.addItem("Heart", branch4, "http://www.cssdrive.com")
	palmtree.addItem("CSS Gallery", branch4, "http://www.cssdrive.com") //Add this item to branch4
	palmtree.addItem("Web Design News", branch4, "http://www.cssdrive.com/index.php/news/") //Add this item to branch3
	palmtree.addItem("CSS Compressor", branch4, "http://www.cssdrive.com/index.php/main/csscompressor/") //Add this item to branch3
palmtree.addItem("Ajaxian", "", "http://ajaxian.com/")
palmtree.treetop.draw(); //REQUIRED LINE: Initalize tree


</script>

  </body>
</html>
Thank YOu.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you're echoing the javascript outside your script tags
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

Hi
Kieran Huggins wrote:you're echoing the javascript outside your script tags
Then could you please tell me how can i echo the values inside the script tags?

Thank You very much for the information.

Thank you.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

Try this

Code: Select all

<script type="text/javascript"> 
<!-- TreeView Demo 3 //--> 
var palmtree=new jktreeview("tree3") 
palmtree.addItem("Coding Forums", "", "http://www.codingforums.com") 
palmtree.addItem("PHP Reference", "", "http://www.php.net") 
palmtree.addItem("Mozilla Dev Center", "", "http://developer.mozilla.org/en/docs/Main_Page") 
var branch4=palmtree.addItem("CSS Drive") //A TREE BRANCH WITH NO URL FOR ITSELF 
<?php $sr = get_result1("sub_cat",cat_name,"Love Hearts");  while($rr = mysql_fetch_array($sr)){ 
echo "palmtree.addItem('".$rr['s_cat_name']."', branch4, 'http://www.cssdrive.com')"; }  ?> 
    palmtree.addItem("love134d", branch4, "http://www.cssdrive.com") 
        palmtree.addItem("Heart", branch4, "http://www.cssdrive.com") 
        palmtree.addItem("CSS Gallery", branch4, "http://www.cssdrive.com") //Add this item to branch4 
        palmtree.addItem("Web Design News", branch4, "http://www.cssdrive.com/index.php/news/") //Add this item to branch3 
        palmtree.addItem("CSS Compressor", branch4, "http://www.cssdrive.com/index.php/main/csscompressor/") //Add this item to branch3 
palmtree.addItem("Ajaxian", "", "http://ajaxian.com/") 
palmtree.treetop.draw(); //REQUIRED LINE: Initalize tree 


</script>
User avatar
dharprog
Forum Contributor
Posts: 126
Joined: Fri Oct 27, 2006 12:20 am

Post by dharprog »

Hi

If i use that php code inside the script it is not displaying anything except that heading "Folding TreeView Menu demo: More info"

Thank you.
Post Reply