How can I overtake the fieldvalues of city and the first part of the
phonenumber. It should read out the value of the zipfield and check them
with the content of the table "ort". If there is found a recordset with
the same plz the formfields city and the the field "vorwahl" should get
the values of the fields of the recordset.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Inserting databasecontent within the same form
am 27.09.2007 03:32:06 von Niel Archer
> How can I overtake the fieldvalues of city and the first part of the
> phonenumber. It should read out the value of the zipfield and check them
> with the content of the table "ort". If there is found a recordset with
> the same plz the formfields city and the the field "vorwahl" should get
> the values of the fields of the recordset.
I'm having troubling understanding exactly what you want and I don't
have time to decipher all the code in the hope it will tell me. My best
guess is you want to use the zipcode from one table, to automatically
add the city name into a form from another table. If that is so, you
can do it with your query using a join.
SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
USING (zipcode)
This assumes that `zipcode` exists in both tables and is unique in the
"City" table. You should also process the City.name and City.vorwahl
results for NULL results where `zipcode` does not exist in the "City"
table.
--
Niel Archer
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Inserting databasecontent within the same form
am 27.09.2007 10:22:51 von Ruprecht Helms
Hi Niel,
> SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
> USING (zipcode)
I'm understanding you this is a way for designing the sql-statement.
My customer want that they have inserted the city after typing in the
zipcode in the zipfield. The city should be searched in a database and
inserted in the field city automaticly.
I think the only way is to do that with some ajax-code combined with a
short phpscript.
Actually I have these codes, but the automatic inserting fails, I don't
know why.
---------------------
ajax.js
function Ajax() {
//Eigenschaften deklarieren und initialisieren
this.url="";
this.params="";
this.method="GET";
this.onSuccess=null;
this.onError=function (msg) {
alert(msg)
}
}
Ajax.prototype.doRequest=function() {
//Ãeberpruefen der Angaben
if (!this.url) {
this.onError("Es wurde kein URL angegeben. Der Request wird
abgebrochen.");
return false;
}
if (!this.method) {
this.method="GET";
} else {
this.method=this.method.toUpperCase();
}
//Zugriff auf Klasse für readyStateHandler ermöglichen
var _this = this;
//XMLHttpRequest-Objekt erstellen
var xmlHttpRequest=getXMLHttpRequest();
if (!xmlHttpRequest) {
this.onError("Es konnte kein XMLHttpRequest-Objekt erstellt werden.");
return false;
}
//Fallunterscheidung nach Ãbertragungsmethode
switch (this.method) {
case "GET": xmlHttpRequest.open(this.method,
this.url+"?"+this.params, true);
xmlHttpRequest.onreadystatechange = readyStateHandler;
xmlHttpRequest.send(null);
break;
case "POST": xmlHttpRequest.open(this.method, this.url, true);
xmlHttpRequest.onreadystatechange = readyStateHandler;
xmlHttpRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
xmlHttpRequest.send(this.params);
break;
}
//Private Methode zur Verarbeitung der erhaltenen Daten
function readyStateHandler() {
if (xmlHttpRequest.readyState < 4) {
return false;
}
if (xmlHttpRequest.status == 200 || xmlHttpRequest.status==304) {
if (_this.onSuccess) {
_this.onSuccess(xmlHttpRequest.responseText,
xmlHttpRequest.responseXML);
}
} else {
if (_this.onError) {
_this.onError("["+xmlHttpRequest.status+"
"+xmlHttpRequest.statusText+"] Es trat ein Fehler bei der
Datenbertragung auf.");
}
}
}
}
//Gibt browserunabhängig ein XMLHttpRequest-Objekt zurück
function getXMLHttpRequest()
{
if (window.XMLHttpRequest) {
//XMLHttpRequest für Firefox, Opera, Safari, ...
return new XMLHttpRequest();
} else
if (window.ActiveXObject) {
try {
//XMLHTTP (neu) für Internet Explorer
return new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
//XMLHTTP (alt) für Internet Explorer
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
return null;
}
}
}
return false;
}
-----------------------------------------
einfuegen.js
//Instanz der Klasse Ajax erzeugen und mit der Datenübertragung starten
function load()
{
$result=mysql_db_query($datenbank,"SELECT * from Orte WHERE PLZ = '$plz'");
while ($row=mysql_fetch_object($result)){
$ort= $row->Bezeichnung;
}
echo $ort;
?>
-----------------------------------------
in the source-phpscript that do the request I have this
html-header
databaseconnection
....
....
some formcode
....
PLZ
Ort
Ort
....
Regards,
Ruprecht Helms
Web: http://www.rheyn.de
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Inserting databasecontent within the same form
am 28.09.2007 01:48:00 von Niel Archer
Hi Ruprecht,
> > SELECT Kunden.*, City.name, City.vorwahl FROM Kunden LEFT JOIN City
> > USING (zipcode)
>
> I'm understanding you this is a way for designing the sql-statement.
Yes.
> My customer want that they have inserted the city after typing in the
> zipcode in the zipfield. The city should be searched in a database and
> inserted in the field city automaticly.
> I think the only way is to do that with some ajax-code combined with a
> short phpscript.
>
> Actually I have these codes, but the automatic inserting fails, I don't
> know why.
Dynamically changing the fields, I'm afraid I can't help. You would be
better trying a list dedicated to ajax.
--
Niel Archer
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php