Question: Include a select list of team names from the teams table created in a
ID: 3834380 • Letter: Q
Question
Question:
Include a select list of team names from the teams table created in a previous assignment (which is shown below!). Use AJAX to return the row from the database based (THIS IS THE PART I AM HAVING TROUBLE) on the team name selected in the select list. Can use the team id or the team name to perform the selection. Display the row in a table consisting of the column heading and then the row of data.
Work I have done so far:
---------------------------------TEAMS TABLE-------------------------------------
ID - Team Name - City - Best Player - Year Formed - Website<br>
01 - Team1 - City1 - Player1 - 2010 - team1.com<br>
02 - Team2 - City2 - Player2 - 2011 - team2.com<br>
03 - Team3 - City3 - Player3 - 2012 - team3.com<br>
04 - Team4 - City4 - Player4 - 2013 - team4.com<br>
-------------------------------------PHP FILE--------------------------------
<script>
function showUser(str) {
if (str=="") {
document.getElementById("txtHint2").innerHTML="";
return;
}
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (this.readyState==4 && this.status==200) {
document.getElementById("txtHint2").innerHTML=this.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<form>
<select name="users">
<option value="">Select a team:</option>
<option value="1">Team1</option>
<option value="2">Team2</option>
<option value="3">Team3</option>
<option value="4">Team4</option>
</select>
</form>
<br>
<div id="txtHint2"><b>Team record will be displayed here.</b></div>
-----------------GETUSER.PHP FILE-------------------------
<!DOCTYPE html>
<html>
<head>
<style>
table {
width: 100%;
border-collapse: collapse;
}
table, td, th {
border: 1px solid black;
padding: 5px;
}
th {text-align: left;}
</style>
</head>
<body>
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','username','password','my_db');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="SELECT * FROM user WHERE id = '".$q."'";
$result = mysqli_query($con,$sql);
echo "<table>
<tr>
<th>TeamName</th>
<th>TeamID</th>
<th>City</th>
<th>BestPlayer</th>
<th>Year Formed</th>
<th>website</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['TeamName'] . "</td>";
echo "<td>" . $row['TeamID'] . "</td>";
echo "<td>" . $row['City'] . "</td>";
echo "<td>" . $row['BestPlayer'] . "</td>";
echo "<td>" . $row['YearFormed'] . "</td>";
echo "<td>" . $row['Website'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
</body>
</html>
--------------------------------------PROBLEM I AM HAVING-----------------------------------------
I am havig creating the database! I was trying to just adjust the select options so that it would just show the whole row when selected instead of going through the database it would already be pre-typed but I am having trouble with that. I know that showing me how to connect to a server is hard so the help I need is when a team is selected, it will show a table with the row selected along with the coloums labeled above them
Thank you very much for your time!!
Explanation / Answer
<p> <input type="button" value="Add Passenger" /> <input type="button" value="Remove Passenger" /> <p>(All acions apply only to entries with check marked check boxes only.)</p> </p> <table id="dataTable" class="form" border="1"> <tbody> <tr> <p> <td > <input type="checkbox" name="chk[]" checked="checked" /> </td> <td> <label>Name</label> <input type="text" name="BX_NAME[]"> </td> <td> <label for="BX_age">Age</label> <input type="text" class="small" name="BX_age[]"> </td> <td> <label for="BX_gender">Gender</label> <select id="BX_gender" name="BX_gender"> <option>....</option> <option>Male</option> <option>Female</option> </select> </td> <td> <label for="BX_birth">Berth Pre</label> <select id="BX_birth" name="BX_birth"> <option>....</option> <option>Window</option> <option>No Choice</option> </select> </td> </p> </tr> </tbody> </table>
javascript
function addRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; if(rowCount < 5){ // limit the user from creating fields more than your limits var row = table.insertRow(rowCount); var colCount = table.rows[0].cells.length; for(var i=0; i <colCount; i++) { var newcell = row.insertCell(i); newcell.innerHTML = table.rows[0].cells[i].innerHTML; } }else{ alert("Maximum Passenger per ticket is 5"); } } function deleteRow(tableID) { var table = document.getElementById(tableID); var rowCount = table.rows.length; for(var i=0; i<rowCount; i++) { var row = table.rows[i]; var chkbox = row.cells[0].childNodes[0]; if(null != chkbox && true == chkbox.checked) { if(rowCount <= 1) { // limit the user from removing all the fields alert("Cannot Remove all the Passenger."); break; } table.deleteRow(i); rowCount--; i--; } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.