Jump to content



Recommended Posts

Good evening , I have a problem that gives me headaches ... I saw in your School Site (W3SCHOOLS) section PHP AJAX example that people take from the database . I tried to put the same id " Peter " two other people like an array and don't work.
Ex: when select Peter Griffin appear let's say his family or wife .. any ideea or clue ?
Thanks alot. Have a great day.
function showUser(str) {
    if (str == "") {
        document.getElementById("txtHint").innerHTML = "";
    } else { 
        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;

<select name="users" onchange="showUser(this.value)">
  <option value="">Select a person:</option>
  <option value="1">Peter Griffin</option>
  <option value="2">Lois Griffin</option>
  <option value="3">Joseph Swanson</option>
  <option value="4">Glenn Quagmire</option>
<div id="txtHint"><b>Person info will be listed here...</b></div>



<!DOCTYPE html>
table {
    width: 100%;
    border-collapse: collapse;

table, td, th {
    border: 1px solid black;
    padding: 5px;

th {text-align: left;}

$q = intval($_GET['q']);

$con = mysqli_connect('localhost','peter','abc123','my_db');
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));

$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);

echo "<table>
while($row = mysqli_fetch_array($result)) {
    echo "<tr>";
    echo "<td>" . $row['FirstName'] . "</td>";
    echo "<td>" . $row['LastName'] . "</td>";
    echo "<td>" . $row['Age'] . "</td>";
    echo "<td>" . $row['Hometown'] . "</td>";
    echo "<td>" . $row['Job'] . "</td>";
    echo "</tr>";
echo "</table>";
Edited by silviu60
Link to comment
Share on other sites

hello again,


I wish that when I select for exemple the 1st person Peter Griffin to appear details about other people who might be in his family


1st select:

id Fist Name Last Name AGE Hometown Job


1 Peter Griffin 41 Quahog Brewery

1 Gina Griffin 20 Quahog Manager

1 Alex Griffin 1 Quahog -





2nd select:

id Fist Name Last Name AGE Hometown Job


2 Joseph Swanson 20 London Driver

2 Alexandra Swanson 18 London Maid



somthing like this



ex: Select: Peter Griffin - Gina Griffin

-Alex Griffin


Select: Joseph Swanson: -Alexandra Swanson

-Gigel Swanson




Thanks for replay.

Edited by silviu60
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...