Page 1 of 2

[solved][56K WARN] php and javascript

Posted: Mon May 28, 2007 1:25 pm
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]

Posted: Mon May 28, 2007 1:32 pm
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");

Posted: Mon May 28, 2007 1:32 pm
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?

Posted: Mon May 28, 2007 1:40 pm
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.

Posted: Mon May 28, 2007 1:45 pm
by superdezign
dharprog wrote:In that cat_name is a variable passing.
Did you forget your "$"?

Posted: Mon May 28, 2007 1:50 pm
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.

Posted: Mon May 28, 2007 1:52 pm
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.

Posted: Mon May 28, 2007 2:12 pm
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.

Posted: Mon May 28, 2007 2:21 pm
by dharprog
Hi

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

Image

Thank you.

Posted: Mon May 28, 2007 2:23 pm
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.

Posted: Mon May 28, 2007 11:22 pm
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]

Posted: Tue May 29, 2007 4:59 am
by Kieran Huggins
you're echoing the javascript outside your script tags

Posted: Tue May 29, 2007 6:05 am
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.

Posted: Tue May 29, 2007 6:20 am
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>

Posted: Tue May 29, 2007 6:48 am
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.