Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    PHP in Javascript

    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
    Million Thanks

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    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?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    Another problem

    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

  • #4
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    Code

    <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>

  • #5
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Try putting some code inside of your while loop.

    PHP Code:
             $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 />";

    Last edited by chump2877; 11-29-2006 at 12:50 PM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #6
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    same problem

    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

  • #7
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,027
    Thanks
    2
    Thanked 315 Times in 307 Posts
    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.
    Last edited by CFMaBiSmAd; 11-29-2006 at 01:06 PM.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #8
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    code

    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

  • #9
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,776
    Thanks
    19
    Thanked 155 Times in 146 Posts
    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...
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #10
    New Coder
    Join Date
    Nov 2006
    Location
    INDIA
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem Solved

    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
    -------------------------
    Shailesh Patil
    -------------------------

  • #11
    Regular Coder
    Join Date
    Sep 2006
    Location
    India Mumbai
    Posts
    248
    Thanks
    13
    Thanked 1 Time in 1 Post

    Thanks

    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

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •