...

View Full Version : PHP in Javascript



bhakti_thakkar
11-29-2006, 01:28 PM
hi,
i am loading database value in a javascript tree view. there is a problem of appending quotes to the query variable .The problem is when i try to execute the sql statement in this way it gives me javascript " EXPECTED ) " error
<script language='javascript'>

<?

$doc="select * from documents where commodityid ='$commid' ";
?>


</script>

if i remove the qoutes from the $commid variable there is no javascript error but the query will not get executed.
Please help me in this:confused:
Million Thanks

chump2877
11-29-2006, 01:41 PM
Where is your javascript? :)

I see some PHP inside of some empty <script> tags....I'm guessing you cut out the surrounding javascript, but i would need to see that to see where the error is coming from...

You are receiving a javascript error, right?

bhakti_thakkar
11-29-2006, 01:41 PM
Hi
the problem got solved by replacing the below code of line 10

line10 : $doc=mysql_query("select * from documentation where commodityid =\'$commodityid\' and inspections =\'$inspid\' " );
line11 : while($docrs=mysql_fetch_assoc($docrid)){ }

but now the problem is i am unable to fetch the records in the script.it gives me syntax error for line 11 ???? if i comment it no problem but uncommenting give me an error

badly stuck

Million Thanks

bhakti_thakkar
11-29-2006, 01:43 PM
<script type="text/javascript">
<!--

d = new dTree('d');
comid=document.mainform.commodityid.value;
compid=document.mainform.companyid.value;
//function(id, pid, name, url, title, target, icon, iconOpen, open)
d.add(0,-1,'<?=$db->GetName("commodityname","commoditymst"," commodityid = '$commodityid' ")?>',"commtreeview.php?commodityid="+comid+"&companyid="+compid);
d.add(1,0,'Inspections','example01.html','','icon12.gif');
<?
$insprid=mysql_query("select * from inspection where commodityid ='$commodityid' and companyid='$companyid' ");

$i=20;
while($insprs=mysql_fetch_assoc($insprid)) {
$i++;
$inspid=$insprs['inspectionid'];

$doc=("select * from documentation where commodityid =\'$commodityid\' and inspections =\'$inspid\'");
$docrid=mysql_query($doc);
// while($docrs=mysql_fetch_assoc($docrid)){ }
?>


d.add(<?=$i?>,1,'<?=$doc?>','example01.html');
<? } ?>
d.add(2,0,'Node 2','example01.html');
d.add(3,1,'Node 1.1','example01.html');
d.add(4,0,' <?=$q1?> Node 3','example01.html');

d.add(8,1,'Node 1.2','example01.html');


d.add(9,0,'Templates','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','example01.html');

document.write(d);

//-->
</script>

chump2877
11-29-2006, 01:47 PM
Try putting some code inside of your while loop.


$doc="select * from documentation where commodityid='$commodityid' and inspections='$inspid'";
$docrid=mysql_query($doc);
while($docrs=mysql_fetch_assoc($docrid)){
echo $docrs['column_name']."<br />";
}

bhakti_thakkar
11-29-2006, 01:54 PM
hi,
thanks for ur reply but even though i do it, it give me syntax error
Below are the changes

while($insprs=mysql_fetch_assoc($insprid)) {
$i++;
$inspid=$insprs['inspectionid'];

$doc=("select * from documentation where commodityid =\'$commodityid\' and inspections =\'$inspid\'");
$docrid=mysql_query($doc);
while($docrs=mysql_fetch_assoc($docrid)){
$id=$docrs['documentname'];
} ?>



d.add(<?=$i?>,1,'<?=$id?>','example01.html');

<? } ?>
Thanks and Regards

CFMaBiSmAd
11-29-2006, 02:01 PM
What is the exact error and let us know which line of this code it references???

Edit: Also, escaping the single-quotes within the double-quoted $doc = string is probably an issue.

bhakti_thakkar
11-29-2006, 02:14 PM
hi,
i am displaying data from the database in a tree view where i am trying to display parent child relation ship.
i am getting javascript error of "Synatx error "

the error is on the bolded line :

<script type="text/javascript">
<!--

d = new dTree('d');
comid=document.mainform.commodityid.value;
compid=document.mainform.companyid.value;
//function(id, pid, name, url, title, target, icon, iconOpen, open)
d.add(0,-1,'<?=$db->GetName("commodityname","commoditymst"," commodityid = '$commodityid' ")?>',"commtreeview.php?commodityid="+comid+"&companyid="+compid);
d.add(1,0,'Inspections','example01.html','','icon12.gif');
<?
$insprid=mysql_query("select * from inspection where commodityid ='$commodityid' and companyid='$companyid' ");

$i=20;
while($insprs=mysql_fetch_assoc($insprid)) {
$i++;
$inspid=$insprs['inspectionid'];

$doc=("select * from documentation where commodityid =\'$commodityid\' and inspections =\'$inspid\'");
$docrid=mysql_query($doc);
while($docrs=mysql_fetch_assoc($docrid)){
$id=$docrs['documentname'];
}
?>

d.add(<?=$i?>,1,'<?=$id?>','example01.html');

<? } ?>
d.add(2,0,'Node 2','example01.html');
d.add(3,1,'Node 1.1','example01.html');
d.add(4,0,' <?=$q1?> Node 3','example01.html');

d.add(8,1,'Node 1.2','example01.html');


d.add(9,0,'Templates','example01.html','Pictures I\'ve taken over the years','','','img/imgfolder.gif');
d.add(10,9,'The trip to Iceland','example01.html','Pictures of Gullfoss and Geysir');
d.add(11,9,'Mom\'s birthday','example01.html');

document.write(d);

//-->
</script>

Thanks

chump2877
11-29-2006, 02:24 PM
It's impossible to get a JS error inside a line of PHP with no javascript in it....

view your browser's source code, and that will show you the correct line of JS code to look for your error...you are forgetting that PHP is invisible on the client side...

shaileshpatil
11-29-2006, 03:01 PM
:) Hi All,
the problem got fixed. i just removed the " \ " which i had put previously put in the sql statment on the very first post.

$insprid=mysql_query("select * from inspection where commodityid ='$commodityid' and companyid='$companyid' ");

all is fine now. Thanks for all the extended helps
:D

bhakti_thakkar
11-29-2006, 03:05 PM
Hi All,
the problem got fixed. i just removed the " \ " which i had put previously put in the sql statment on the very first post.
BEFORE:
$doc=mysql_query("select * from documentation where commodityid =\'$commodityid\' and inspections =\'$inspid\' " );

AFTER:
$doc="select * from documentation where commodityid ='$commodityid' and inspections ='$inspid'";

all is fine now. Thanks for all the extended helps

__________________
-------------------------



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum