SitePoint Sponsor

User Tag List

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

    Element clicked id= select*from 'id'

    Hello all. I need to know if I can use ul onclick in external.js to make an Ajax call to file.php that executes mysql_query select * from 'id' of the li element clicked.
    UL EG.
    HTML Code:
    <ul id="jewelry">
    <li id="silver>Silver Jewelry</li>
    <li id="gold">Gold Jewelry</li>
    <li id="silverwithstones">Silver with stones</li>
    </ul>
    file.php
    Code:
    mysql_query=SELECT*FROM '.id.' etc.
    Thanks in advance for any thoughts

  2. #2
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,027
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Which js framework?

  3. #3
    SitePoint Addict
    Join Date
    Dec 2009
    Posts
    221
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good question? I'm runing on WIN XP sp3 IE8 with all the latest updates. How would I find out?

  4. #4
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,027
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Ok, if you are asking that question you are in way over your head. Learn basic PHP first, then worry about AJAX.

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    I'm sure you can. But what is the question exactly? How to make an ajax call (javascript)? Or how to retrieve data from the database (php)?

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

    Thumbs up

    guido2004
    Nice replly. This is the javascript ul onclick that I have
    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);
    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.title==i+' jewelry';//not sure that worked no alert
    alert(document.title);
    document.getElementById('f1').className=i;//just checking the i is silver
    alert(document.getElementsByTagName('div')[6].className);//div class=silver
    }   
    }   
    }
    getproduct.php
    Code:
    $q=$_GET["q"]; // Undefined index:'q' at line 2
    
    $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( ));
    //the bold draws error syntax check sql version syntax etc.


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
  •