PDA

View Full Version : PHP [& mySQL] with JavaScript - Updating Dynamically


AndyL
07-28-2004, 12:39 PM
Hello,

I have a '.PHP' script which asks the user to enter 2 numbers ["Client Reference" & "Matter Suffix"]. I would like .PHP element of the script to query the mySQL d'base 'on the fly' [if possible?], hence updating the screen with the corresponding text description relative to the 2 numbers entered.

I can get the script to do this provided the form in which it all resides is submitted [hence the PHP calls the mySQL query] and reports back the respective text descriptions of the 2 numbers entered, but I would like for it to occur automatically, without a form submission. Is this possible?

So far I have tried to make it happen using JavaScript but I am very aware that PHP is Server-side and JavaScript is Client-side, so I'm having no joy & am quite stuck. Any suggestions please??


<?php
echo "
<html>
<head>
<link rel=\"stylesheet\" type=\"text/css\" href=\"/cgi-bin/style.htm\">
<title>JS Load Test File</title>
</head>

<SCRIPT language=\"JavaScript\">
function getValue(abc)
{
valueEntered = abc;
return $client_name;
}
</SCRIPT>

<BODY>";

if (true == (is_numeric($sclient_ref) and is_numeric($smatter_suffix)))
{
$connection = odbc_connect("AZL","AZLapps","AZL") or
die("Unable to connect");

//get row entries

$result = odbc_exec($connection,"
use p4AZLint select top 1 client.client_name, archive.matter_description
from archive
left join client on client.client_ref = archive.client_ref and volume_number = 0
where archive.client_ref = '$sclient_ref' and archive.matter_suffix = '$smatter_suffix'"
) or
die("Unable to query Database");

while ($row = odbc_fetch_row($result))
{
for ($i = 1; $i <= odbc_num_fields($result); $i++ )
{
$x = odbc_field_name($result,$i);
$$x = odbc_result($result,$i);
}
}
}

echo "
<form method=\"post\" action=\"jsload.php\" name=AZL>
<table>
<tr><td>Select an office: </td>
<td><select name=\"s_office\">
<option value=p4AZL1int selected>London</option>
<option value=p4AZL2int>Manchester</option>
<option value=p4AZL3int>Exeter</option>
</select></td></tr>

<tr><td>Client Reference: </td>
<td><input name=sclient_ref value=\"$sclient_ref\" onChange=\"getValue(this.value)\";> <b>$client_name</b></td></tr>

<tr><td>Matter Suffix: </td>
<td><input name=smatter_suffix value=\"$smatter_suffix\" onChange=\"getValue(this.value)\";> <b>$matter_description</b></td></tr>

<tr valign=top>
<td>Do you want to:</td>
<td><input type=radio name=nvolume value=C checked>close the matter and all its parts<br>
<input type=radio name=nvolume value=P >put away some parts</td>
<tr>
<td></td>
<td><INPUT TYPE=\"SUBMIT\" VALUE=\"Run Enquiry\"></td>
</tr>
</table>
</form>";

?>


In short, I want it to do what it does currently but prior to the user submitting the form.

Many thanks,
Andy

bnovc
07-28-2004, 01:57 PM
No, PHP is server side.

You can have an "onchange='submit();'", but I doubt many people would like that.

You wouldn't want it to do that anyways, it would give users access to your database login information, if it is being submitted via them.

AndyL
07-28-2004, 02:49 PM
Fair enough.

But I would like my webpage to 'dynamically' update with regards to the user's data entered, without having to submit the form first.

Might it be an idea to use '.ASP'? I have limited knowledge of this scripting language but am prepared to learn it/give it a go if it will do the job I require.

Is there an alternative way to query a mySQL d'base [with/out PHP] so that it updates live/'on the fly', without a form submission occurring?

Thanks,
Andy