+ Reply to Thread
Results 1 to 2 of 2

Thread: MySql problems

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    MySql problems

    I have been trying to get this code working and I have hit a stand still. I do not know if it is by my error or the way I am coding the js. Currently it loads correctly half the time and the other half the form shows blank and the load time of each box is slow. If I refresh the page it does not refresh the form data. If there is a better way of coding this other then ajax I am willing to hand out 800 credits for the coding. Any language that works on x10 hosting I am in a crunch to get this finished and it is driveing me nuts.

    Here is a line from the database.
    year make model engine link to products
    "1990","Acura","Integra","4 Cylinder","http://site.com/store"


    Current Form
    Code:
    <form action="conversion_kits.php" method="post" id="myform" onSubmit="return send_query()">
    <table border="1">
    <tr><td>Year</td> <td><select  id="year" name="year" onChange="setdata('setyear','make')" >
    <option id="year1">-Select Year-</option>
    
    </select> </td></tr>
    <tr><td>Make</td> <td><select id="make"  name="make" onChange="setdata('setmake','model')">
    <option id ="make1">-Select Make-</option>
    </select> </td></tr>
    
    
    <tr><td>Model</td> <td>
    <select id="model" name="model" onChange="setdata('setmodel','engine')">
    <option id="model1">-Select Model-</option>
    </select>
    </td></tr>
    
    <tr><td>Engine</td> <td>
    <select id="engine" name="engine">
    <option id="engine1">-Select Model-</option>
    </select>
    </td></tr>
    </table>
    <input type= "submit" name = "go" value="SendQuery">
    </form>
    Current javascript file
    Code:
    
    
    var request = false;
    
    try {
    
      request = new XMLHttpRequest();
    
    } catch (trymicrosoft) {
    
      try {
    
        request = new ActiveXObject("Msxml2.XMLHTTP");
    
      } catch (othermicrosoft) {
    
        try {
    
          request = new ActiveXObject("Microsoft.XMLHTTP");
    
        } catch (failed) {
    
          request = false;
    
        }
    
      }
    
    }
    
    
    
    
    
    if (!request)
    
      alert("Error initializing XMLHttpRequest!");
    
    
    
    var url = 'kits.php';
    
    var set_year =0;
    
    var sid=null;//dont delete or edit
    
    var selectids = new Array("year","make","model","engine");
    
    function setdata(option,id) 
    
    {
    
       resetchoose(id);
    
       sid = id; 
    
       //alert(sid);
    
       
    
       data=getdata(id);
    
       var t=new Date();
    
       var url = "product.php?option="+option+"&time="+t.getTime();
    
       request.open("POST",url, true);
    
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
       request.send(data);
    
       request.onreadystatechange = updateList;
    
       
    
    }
    
    function setyear(option,id) 
    
    {
    
       resetchoose(id);
    
       sid = id; 
    
       //alert(sid);
    
       //data=getdata(id);
    
       var t=new Date();
    
       var url = "product.php?option="+option+"&time="+t.getTime();
    
       request.open("GET",url, true);
    
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
       request.send(null);
    
       request.onreadystatechange = updateList;
    
    }
    
    setyear('allyear','year');
    
    
    
    function send_query()
    
    {
    
       limit = selectids.length;
    
       //alert(limit);
    
       for(var i=0 ; i<limit; i++){
    
          si = document.getElementById(selectids[i]).selectedIndex;
    
          if (si==0){
    
             alert(selectids[i]+' is not selected');
    
             return false;
    
          }
    
       }
    
    }
    
    function getdata(curr)
    
    {
    
       var data = null;
    
       var index =0;
    
       var cs = selectids[index];
    
       val = document.getElementById(cs).value;
    
       data = cs + "=" + encodeURIComponent(val);
    
       if (cs==curr) return data;
    
       index = index+1;
    
       while(curr!=selectids[index]){
    
          
    
          cs = selectids[index];
    
          val = document.getElementById(cs).value;
    
          data = data+"&"+cs + "=" + encodeURIComponent(val);
    
          index = index+1;
    
       }     
    
       return data;
    
    }
    
    function resetchoose(id)
    
    {
    
       curr = id; 
    
       limit = selectids.length;
    
       //alert(limit);
    
       for(var i=0 ; i<limit; i++){
    
          if(curr==selectids[i]) {
    
             var index =i; 
    
             break;
    
             //alert(index)
    
          }
    
       }
    
       for(i=index;i<limit;i++){
    
          rs = selectids[i]
    
          //alert(rs+  'must reset');
    
          mr = document.getElementById(rs);
    
          if (mr!=null)document.getElementById(rs).selectedIndex=0;
    
       }
    
    }
    
    
    
    function updateList() {
    
    
    
       if (request.readyState == 4) {
    
           if (request.status == 200) {
    
            var make=request.responseText.split("|");
    
             //alert(make);
    
             var limit = make.length-1;
             //alert(limit);
             var list =document.getElementById(sid);
    
             var oid = sid+"1"; 
    
             var member = document.getElementById(oid);
             var nvg = document.getElementById(oid);
             member = nvg.nextSibling;
    
               
    
                while((member!= null))
    
               {
                   
                   list.removeChild(member);
    
                   member=nvg.nextSibling;
    
               }
    
             
    
             for(var i=0; i<limit; i++){
    
                value = make[i];
    
                //alert(value);
    
                var newitem=document.createElement("option");
    
                newitem.setAttribute("value", value);
    
                var text = document.createTextNode(value);
    
                newitem.appendChild(text);
    
                 list.appendChild(newitem);
    
           } 
    
           } else if (request.status == 404) {
    
             alert("URL does not exist.");
    
           } else {
    
             //alert("Status is: " + request.status);
    
           }
    
         }      
    
    }
    
    //resetchoose(-1);
    Edit:
    I found the error you can close the thread this is the new code.


    Code:
    var request = false;
    
    try {
    
      request = new XMLHttpRequest();
    
    } catch (trymicrosoft) {
    
      try {
    
        request = new ActiveXObject("Msxml2.XMLHTTP");
    
      } catch (othermicrosoft) {
    
        try {
    
          request = new ActiveXObject("Microsoft.XMLHTTP");
    
        } catch (failed) {
    
          request = false;
    
        }
    
      }
    
    }
    
    
    
    
    
    if (!request)
    
      alert("Error initializing XMLHttpRequest!");
    
    
    
    var url = 'deneme2.php';
    
    var set_year =0;
    
    var sid=null;//dont delete or edit
    
    var selectids = new Array("year","make","model","engine");
    
    function setdata(option,id) 
    
    {
    
       resetchoose(id);
    
       sid = id; 
    
       //alert(sid);
    
       //alert("test");
    
       data=getdata(id);
    
       var t=new Date();
    
       var url = "db.php?option="+option+"&time="+t.getTime();
    
       request.open("POST",url, true);
    
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
       request.send(data);
    
       request.onreadystatechange = updateList;
    
       
    
    }
    
    function setyear(option,id) 
    
    {
       resetchoose(id);
    
       sid = id; 
    
       //alert(sid);
    
       //data=getdata(id);
    
       var t=new Date();
    
       var url = "db.php?option="+option+"&time="+t.getTime();
    
       request.open("GET",url, true);
    
       request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    
       request.send(null);
    
       request.onreadystatechange = updateList;
    
    }
    
    setyear('allyear','year');
    
    
    
    function send_query()
    
    {
    
       limit = selectids.length;
    
       //alert(limit);
    
       for(var i=0 ; i<limit; i++){
    
          si = document.getElementById(selectids[i]).selectedIndex;
    
          if (si==0){
    
             alert(selectids[i]+' is not selected');
    
             return false;
    
          }
    
       }
    
    }
    
    function getdata(curr)
    
    {
    
       var data = null;
    
       var index =0;
    
       var cs = selectids[index];
    
       val = document.getElementById(cs).value;
    
       data = cs + "=" + encodeURIComponent(val);
    
       if (cs==curr) return data;
    
       index = index+1;
    
       while(curr!=selectids[index]){
    
          
    
          cs = selectids[index];
    
          val = document.getElementById(cs).value;
    
          data = data+"&"+cs + "=" + encodeURIComponent(val);
    
          index = index+1;
    
       }     
    
       return data;
    
    }
    
    function resetchoose(id)
    
    {
    
       curr = id; 
    
       limit = selectids.length;
    
       //alert(limit);
    
       for(var i=0 ; i<limit; i++){
    
          if(curr==selectids[i]) {
    
             var index =i; 
    
             break;
    
             //alert(index)
    
          }
    
       }
    
       for(i=index;i<limit;i++){
    
          rs = selectids[i]
    
          //alert(rs+  'must reset');
    
          mr = document.getElementById(rs);
    
          if (mr!=null)document.getElementById(rs).selectedIndex=0;
    
       }
    
    }
    
    
    
    function updateList() {
    
    
    
       if (request.readyState == 4) {
    
           if (request.status == 200) {
    //alert(request.responseText);
            var make=request.responseText.split("|");
    
             //alert(make);
    
             var limit = make.length-1;
             //alert(limit);
             var list =document.getElementById(sid);
    
             var oid = sid+"1"; 
              //alert(oid);
             var member = document.getElementById(oid);
             var nvg = document.getElementById(oid);
             member = nvg.nextSibling;
                while((member!=null))
               {
                   list.removeChild(member);
                   member=nvg.nextSibling;
               }
    
             
    
             for(var i=0; i<limit; i++){
    
                value = make[i];
    
                //alert(value);
    
                var newitem=document.createElement("option");
    
                newitem.setAttribute("value", value);
    
                var text = document.createTextNode(value);
    
                newitem.appendChild(text);
    
                 list.appendChild(newitem);
    
           } 
    
           } else if (request.status == 404) {
    
             alert("URL does not exist.");
    
           } else {
    
             //alert("Status is: " + request.status);
    
           }
    
         }      
    
    }
    
    //resetchoose(-1);
    Last edited by driveflexfuel; 11-18-2008 at 03:57 PM. Reason: Automerged Doublepost

  2. #2
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: MySql problems

    Good but did you give yourself 800 creds too?
    Don't get me wrong as I believe if and when I help someone I also help myself whereby whatever someone learns I also learn.

    But I will also accept credits or reps if you really want to part with it.

+ Reply to Thread

Similar Threads

  1. MySQL Problems
    By tearsfall in forum Programming Help
    Replies: 3
    Last Post: 09-01-2008, 02:12 AM
  2. MySQL Issues Here
    By Corey in forum Service Alerts
    Replies: 304
    Last Post: 01-06-2008, 09:10 PM
  3. MySQL Problems - Refreshing the cPanel Page
    By nyllo in forum Feedback and Suggestions
    Replies: 1
    Last Post: 12-24-2007, 01:07 AM
  4. in here MySQL version????
    By winUSD in forum Free Hosting
    Replies: 4
    Last Post: 05-09-2006, 08:44 AM
  5. mysql problems
    By NewFuture in forum Free Hosting
    Replies: 1
    Last Post: 06-26-2005, 10:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers