SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Element clicked id= select*from 'id'

    Hi Guy's, back again to beg mercy of the script gods. Please let me know if this even works. I'm trying to get a ul onclick function that will use the uls li element clicked id to write SELECT * FROM ".id."
    External.js
    Code:
    function getproduct(i){
    if(i=' '){
    document.getElementById('f1').innerHTML=' ';
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("f1").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","getproduct.php?q="+i,true);
    xmlhttp.send();
    }
     
    var jewelry= document.getElementById('jewelry').childNodes;   
    for (i = 0; i < jewelry.length; i++) {   
    if (jewelry[i].className == 'item') {  // excludes class="item disabled" 
    jewelry[i].onclick = function() {   
    alert(this.id+': Is sending your request.');  // this actually gets the right id
    var i=this.id;
    alert(i); //alerts correct id
    getproduct(i);
    }   
    }   
    } 
    
    window.onload=getproduct();
    getproduct.php
    Code:
    <?php
    $q=$_GET["q"]; // error "undefined index":q at line 1 syntax error check your etc.
    
    $link=mysql_connect("localhost","root","root")or die(mysql_error( ));
    
    mysql_select_db("bwi",$link) or die(mysql_error( ));
    
    $query=mysql_query("SELECT * FROM '.q.'")or die(mysql_error( ));

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    if(i=' '){

    Are you really assigning a space to i after going to all that trouble to set it to the id or have you simply left out the other =

    Try coding it as

    if(' '===i){
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Mr. Chapman glad to hear from you, will check it out as soon as I get back from walkin the dogs. Something like ' '===i checks to see if the string contains i ? Brilliant. Wierd but brilliant. As long as 'SELECT*FROM '.q.' is a standard practice for get or post, I'll be happier than I can say.

  4. #4
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    Hi Steve Just tried your if statement and drew this error again. I'm not sure but I think it might be the SELECT*FROM '".q."'" syntax? even though the error reffers to line one.
    Notice: Use of undefined constant q - assumed 'q' in D:\use_ide_1\UniServer\www\getproduct.php on line 8
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''q'' at line 1
    External.js
    Code:
    function getjewelry(i){
    if(' '===i){
    document.getElementById('f1').innerHTML=' ';
    }
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("f1").innerHTML=xmlhttp.responseText;
    }
    }
    xmlhttp.open("GET","getproduct.php?q="+i,true); //might be problem?
    xmlhttp.send();
    }
     
    var jewelry= document.getElementById('jewelry').childNodes;   
    for (i = 0; i < jewelry.length; i++) {   
    if (jewelry[i].className == 'item') {  // excludes class="item disabled" 
    jewelry[i].onclick = function() {   
    alert(this.id+': Is sending your request.');  // this actually gets the right id
    var i=this.id;
    alert(i); //alerts correct id
    getjewelry(i);
    document.getElementById('f1').className='silver'; //actually loads logo class silver bcground img in f1?
    //when I use className='i' f1 div just shows error
    alert(f1.innerTML); //returns 'undefined' ?
    }   
    }   
    }
    getproduct.php
    Code:
    <?php
    $q=$_GET["q"]; //syntax to use near ''q'' at line 1
    $link=mysql_connect("localhost","root","root")or die(mysql_error( ));
    
    mysql_select_db("bwi",$link) or die(mysql_error( ));
    //Use of undefined constant q - assumed 'q' line 8
    $query=mysql_query("SELECT * FROM '".q."'")or die(mysql_error( ));
    Defining the constant 'i' as 'q' might be the problem
    ("GET","getproduct.php?q="+i,true);
    Last edited by Heinz Stapff; Aug 23, 2011 at 08:24. Reason: //actually loads logo bcground img in f1?


Bookmarks

Posting Permissions

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