Forum Moderators: coopster

Message Too Old, No Replies

Need Help. =(

         

Wishbone2712

4:30 pm on Nov 30, 2007 (gmt 0)



I have problem while developing the code..
The Form Looks like this:

ID :
Description :
Price :

what i want this code do is, if the user enters the ID and click the display button, the description and price details appears without reloading the page.

I've already load the table and store them temporary in the arrays. So i think what i need to do now is to Retrieve those Data.

My friend says that, i need javascript to do this, but unfortunately, i dont have any knowledge about java script, plus im also a newbie in php =(

can someone kindly solve my problem =(

Thank you for your help guys =)

<html>
<body>
<?
include ("databaseconfig.php");
$query="SELECT * FROM bahan ";
$result=mysql_query($query);
$num=mysql_num_rows($result);
mysql_close();

////Stores the records in an Array
$i=0;
$x=0;
while ($i < $num)
{
$ID[$x]=mysql_result($result,$i,"ID");
$Deskripsi[$x]=mysql_result($result,$i,"Deskripsi");
$Harga[$x]=mysql_result($result,$i,"Harga");
$i++;
$x++;

}
$a = "";/// <--- The Value of a is based on the user input.. but i have no idea how to do that.. is using javascript possible?
echo"
<form name='form1' method='post' action=''>
<p>ID
<input type='text' name='ID' value ='$ID[$a]'>
</p>
<p>Harga
<input type='text' name='Harga' value='$Deskripsi[$a]'>
</p>
<p>Deskripsi
<input type='text' name='Deskripsi' value='$Harga[$a]'>
</p>
<p>
<input type='button' name='Submit' value='Display' onClick='Display()'>
</p>
</form>"
?>
</body>
</html>
<script language="javascript">
<!--

function Ambil() ///<---- i got no idea about the java script....
{
var ID = document.getElementById("ID");
}

-->

willybfriendly

4:38 pm on Nov 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what i want this code do is, if the user enters the ID and click the display button, the description and price details appears without reloading the page.

Your friend is correct. PHP runs on the server. The POST data needs to be returned to the server for processing and then sent back to the browser to be displayed.

Without a java script or AJAX solution, there will need to be a page reload.

Wishbone2712

4:42 pm on Nov 30, 2007 (gmt 0)



Hmmm okay,
but since i already store the data temporarily in the arrays, i dont have to reload the page again right?

i use the java script to send the row number...

is it possible to create this?

Wishbone2712

6:20 pm on Nov 30, 2007 (gmt 0)



Oh,IS there a way to convert those PHP arrays into Java Script arrays, i think this problem will be solved with that..

d40sithui

6:47 pm on Nov 30, 2007 (gmt 0)

10+ Year Member



i know js can get simple variables from php, but with arrays, im not so sure.
like for simple variables, you can do something like this in your php file:

<script>
var string1 = <? echo $string1;?>
</script>

the thing is, with arrays, you will need to write a loop or loops that goes through the php array and the js array. so its get more complicated since you wont know the lenght of the php array and you wont be able to pass the current array location to the js array.
actually, this may work, but i havent tried it.


<script>
<?
for ($i = 0; $i < sizeof($myArray); $i++){
echo "jsArr[$i] = $myArray[$i];\n";
}
?>
</script>

i really think you're better off using ajax. its not that hard to learn. and with it, problems like this will be cake. plus do you really want people to see the data when they click on view source?

Wishbone2712

6:38 am on Dec 1, 2007 (gmt 0)



Of course i want to learn ajax but the due date for this assignment is on monday... =(

anyway

is there any way to load PHP array inside the javascript?