CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> General/Other

 [SOLVED] RETRIEVING MYSQL DATABASE WITH AJAX SOLUTION

Print topic Send  topic

Author Message
CodeChargeMVP

Posts: 473
Posted: 05/04/2010, 3:24 AM

Hello,

I´m trying to apply an ajax solution, i´ve got text box by the user write a town on it

so when on click of other button from the window shows the code related to that town

in other textbox anywghere in the window, i attach the code:

This is the call to the ajax code:

//on click of a button this condition makes true

else if (window.document.getElementById("mahp_municipios_municipios_MunNom").value != "")
{

BuscarCodigo(window.document.getElementById("mahp_municipios_municipios_MunNom").value);

}



//Código AJAX

var xmlhttp;

function BuscarCodigo(codigo)
{

try
{

//Código para IE7,Firefox,Chrome,Opera,Safari
if (window.XMLHttpRequest)
{
//Asi creo el objeto XMLHttpRequest
xmlhttp=new XMLHttpRequest();
EnviarPeticion();

}
//Código para IE6,IE5
else
{
//Asi creo el objeto ActiveXObject
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
EnviarPeticion();

}

}
catch(ex)
{


alert("Su navegador no soporta este objeto");

}

}


//Aquí configuro los parámetros de la petición y realizo el envio de la misma
function EnviarPeticion()
{

xmlhttp.open("GET","getcode.php?q="+codigo,true);
xmlhttp.onreadystatechange=ProcesaDatos();
xmlhttp.send();


}

//tratamiento de la respuesta
function ProcesaDatos()
{

if(xmlhttp.readyState==4 && xmlhttp.status==200)
{


window.document.getElementById("mahp_municipiosMahpMunCod").value = xmlhttp.responsetext;
//window.document.getElementById("txtHint").innerHTML=xmlhttp.responsetext;

}

}




//PHP page

<?php

$q=$_GET["q"];

$con = mysql_connect ('localhost','','');

if (!$Con)
{

die ('Could not connect: ' . mysql_error());

}


mysql_select_db("",$con);

$sql="SELECT MunCod FROM municipios WHERE MunNom = '".$q."'";

$result = mysql_query($sql);


mysql_close($con);
?>


In theory, this could work out, but i´ve got some dummy questions, i´m just a beginner programmer,

¿do i´ve to create a blank page on codecharge and add on the php section the php code,

seems obviously, but codecharge generates there some php code, how do i make sure than

the code than i add will be executed?

¿How do i return the sql result from the PHP code, still unkwown to me?

Thank you very much in advance.

_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
ckroon

Posts: 869
Posted: 05/04/2010, 1:54 PM

Put your custom code in the Before Show Event of the Page.

(events Tab, Before Show->Add Code)
_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/05/2010, 2:50 AM

Quote ckroon:
Put your custom code in the Before Show Event of the Page.

(events Tab, Before Show->Add Code)

¿My custom code? ¿You mean the javascript or the php?.

¿And why on the before show?


_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
ckroon

Posts: 869
Posted: 05/06/2010, 9:17 AM

javascript in the HTML of page

PHp in the Before Show event of the page
_________________
Walter Kempees...you are dearly missed.
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/07/2010, 2:00 AM

Quote ckroon:
javascript in the HTML of page

PHp in the Before Show event of the page


Hello Ckroon,

I still don�t understand why on the before show of the page � which page?

Master_M.php or getcode.php

I think i didn�t explain well what i want,I�ll do it again:


Somewhere an ajax solution is launch by this code:

// I get the value from a textbox where the user writes the town, now i call to the ajax solution,

to get into the database and retrieve the code related to that town.

codigo = window.document.getElementById("mahp_municipios_municipios_MunNom").value;

BuscarCodigo(codigo);



//C�digo AJAX

var codigo = "";
var xmlhttp;

function BuscarCodigo(codigo)
{

try
{


if(window.ActiveXObject)
{
//C�digo para IE6,IE5
alert("entra 1");
//Asi creo el objeto ActiveXObject
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");

}
else if ((window.XMLHttpRequest) || (typeof XMLHttpRequest) != undefined)
{
//C�digo para IE7,Firefox,Chrome,Opera,Safari
alert("entra 2");
//Asi creo el objeto XMLHttpRequest
xmlhttp=new XMLHttpRequest();

}
else
{

//navegadores sin soporte Ajax
alert("Su navegador no tiene soporte para AJAX");
return;
}

EnviarPeticion();




}
catch(ex)
{


alert("Su navegador no soporta este objeto");

}

}


//Aqu� configuro los par�metros de la petici�n y realizo el envio de la misma
function EnviarPeticion()
{

alert("llega a la peticion");
xmlhttp.open("GET","getcode.php?q="+codigo,true);
alert("ya ha hecho la peticion");
xmlhttp.onreadystatechange=ProcesaDatos();
xmlhttp.send();


}

//tratamiento de la respuesta
function ProcesaDatos()
{

if(xmlhttp.readyState==4 && xmlhttp.status==200)
{

window.document.getElementById("mahp_municipiosMahpMunCod").value = xmlhttp.responsetext;
//window.document.getElementById("txtHint").innerHTML=xmlhttp.responsetext;

}

}



This code works all good but when it gets to this line:
xmlhttp.open("GET","getcode.php?q="+codigo,true);
somenthing went wrong

and here the php code

//Configuraci�n de la conexion a la base de datos
$bd_host = "localhost";
$bd_usuario = "admin";
$bd_password = "adm";
$bd_base = "dgpolde1";

$q=$_GET["q"];

$con = mysql_connect ($bd_host,$bd_usuario,$bd_password);

if (!$Con)
{

die ('Could not connect: ' . mysql_error());

}


mysql_select_db($bd_base,$con);

$sql="SELECT MunCod FROM municipios WHERE MunNom = '".$q."'";

$result = mysql_query($sql);

//Muestra los datos consultados


mysql_close($con);




�How do i show the $result on a textbox from the window?

Greets in advance.







_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
joejac

Posts: 242
Posted: 05/08/2010, 7:41 PM

Hello CodeChargeMVP,

I would suggest that you could get your task easier if you use all Ajax power of CCS Ajax Features :
1.- Open the CCS Help and search for "Ajax" and read all the topics
2.- Download the "AJAX Examples created with CodeCharge Studio 4.0" and play with them and look how they work, I think it is a very good time invested
http://examples.codecharge.com/
3.- Rethink your project to create it with CCS 4 Ajax Features.

Hope this can help you.
Best regards
joejac
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/10/2010, 4:45 AM

Quote joejac:
Hello CodeChargeMVP,

I would suggest that you could get your task easier if you use all Ajax power of CCS Ajax Features :
1.- Open the CCS Help and search for "Ajax" and read all the topics
2.- Download the "AJAX Examples created with CodeCharge Studio 4.0" and play with them and look how they work, I think it is a very good time invested
http://examples.codecharge.com/
3.- Rethink your project to create it with CCS 4 Ajax Features.

Hope this can help you.
Best regards
joejac

Hello JoeJac,

Thank you very much for your suggestion,

I reminded than I still have to learn a lot about CodeCharge And all new Developing

technologies,so I´´ve been taking a look to the examples and I think it´ll help very much,

I´ll back in the comming days to let us know if i finally resolve the issue.

_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message
CodeChargeMVP

Posts: 473
Posted: 05/12/2010, 8:01 AM

Helo JoeJac,

The Ajax Features, just works all good,

I´ve adapt an example from the link than you gave me to my project, using just the steps: (2,8,9 and 10)

and it works really good.

This is the example than i take into consideration:

http://examples.codecharge.com/Ajax/DependentListBox2_desc.php

I´ve check the results with a select into my database and we´ve realise than the dependant listbox do his task,

but there´s a register from the master dependant list box which has more than 200 results on the slave dependant list box

and it only shows 75 there, so I got a question:

¿is there any option or anything which is restricting the number of results from the slave dependant list box?

Thank you very much in advance.




Quote CodeChargeMVP:
Quote joejac:
Hello CodeChargeMVP,

I would suggest that you could get your task easier if you use all Ajax power of CCS Ajax Features :
1.- Open the CCS Help and search for "Ajax" and read all the topics
2.- Download the "AJAX Examples created with CodeCharge Studio 4.0" and play with them and look how they work, I think it is a very good time invested
http://examples.codecharge.com/
3.- Rethink your project to create it with CCS 4 Ajax Features.

Hope this can help you.
Best regards
joejac

Hello JoeJac,

Thank you very much for your suggestion,

I reminded than I still have to learn a lot about CodeCharge And all new Developing

technologies,so I´´ve been taking a look to the examples and I think it´ll help very much,

I´ll back in the comming days to let us know if i finally resolve the issue.


_________________
Best Regards
Entrepeneur | NT Consultant
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.