/    Sign up×
Community /Pin to ProfileBookmark

how to get value from table

hi..this is my file name run.php

[CODE]
<html>
<head>
<script type=”text/javascript”>
function showUser(str)
{
if (str==””)
{
document.getElementById(“txtHint”).innerHTML=””;
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”getuser.php?q=”+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<?php
$host=”127.0.0.1″; // Host name
$username=”root”; // Mysql username
$password=””; // Mysql password
$db_name=”ofcccv3″; // Database name

// Connect to server and select databse.
mysql_connect(“$host”, “$username”, “$password”)or die(“cannot connect”);
mysql_select_db(“$db_name”)or die(“cannot select DB”);

$query = “SELECT * FROM car”;

$result = mysql_query($query) or die(mysql_error());

?>

<form>

<select name=”users” onchange=”showUser(this.value)”>

<?php

// Print out the contents of each row into a table
while($row = mysql_fetch_array($result))
{
echo “<option value=”.$row[‘id’].”>” . $row[‘plat’] . “</option>”;
}

$result = mysql_query($query) or die(mysql_error());

?>
</select>

</form>

<br />
<div id=”txtHint”><b>Person info will be listed here.</b></div>
<p></p>
<input name=”engineCC” type=”text” >
</body>
</html>
[/CODE]

and also getuser.php file:

[CODE]
<?php
$q=$_GET[“q”];

$con = mysql_connect(‘127.0.0.1’, ‘root’, ”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db(“ofcccv3″, $con);

$sql=”SELECT * FROM car WHERE id = ‘”.$q.”‘”;

$result = mysql_query($sql);

echo “<table border=’1’>
<tr>
<th>CAR PLAT NUMBER</th>
<th>CAR MODEL</th>
<th>CAR CC</th>
<th>CAR TRANSMISSION</th>
</tr>”;

while($row = mysql_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘plat’] . “</td>”;
echo “<td>” . $row[‘type’] . “</td>”;
echo “<td>” . $row[‘cc’] . “</td>”;
echo “<td>” . $row[‘trans’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;

mysql_close($con);
?>
[/CODE]

::after i run the run.php file.it is success for me to retrieve the data from database using a drop down list..next, what i need to do to make sure that the echo “<td>” . $row[‘cc’] . “</td>”; value also appear in the ‘engineCC text box’
Thanks you for your time

to post a comment
HTML

0Be the first to comment 😎

×

Success!

Help @kidphantom spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...