I have a script (below) that consists of a form using javascript that shows an array in a table below it once a number is chosen.
What i would like to know is can i turn the array into a form as well with the same data but include a checkbox next to each field, so i can $POST the selections to another table in the DB.

//////FORM

<div class="TabbedPanelsContent">
<form>
Select a Round:
<select name="round" onchange="showRound(this.value)">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</form>
<p>
<div id="txtHint"></div>
</p>
</div>

/////javascript

var xmlHttp
function showRound(str)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="select_round/getround.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}


//// PHP

<?php
$q=$_GET["q"];

$con = mysql_connect('localhost', 'username', 'pass');
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

$sql="SELECT * FROM fixtures WHERE round = '".$q."'";

$result = mysql_query($sql);
echo "<table border='0'>
<tr>
<th>Game</th>
<th align='center'>Home</th>
<th align='center'>Away</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<form>";
echo "<td width='25' align='center'>" . $row . "</td>";
echo "<td width='150'>" . $row . "</td>";
echo "<td width='150'>" . $row . "</td>";
echo "</form>";
echo "</tr>";
}

echo "</table>";


mysql_close($con);
?>

Hi Anasta,
I must be missing something because to me, the answer is very simple:

...
echo '<form action="saveme.php">';
echo "<tr>";
echo '<td><input type="checkbox" name="gameId" value="'.$row['id'].'"></td>';
echo "<td width='25' align='center'>" . $row['game'] . "</td>";
echo "<td width='150'>" . $row['home'] . "</td>";
echo "<td width='150'>" . $row['away'] . "</td>";
echo "</tr>";
echo "</form>";
...

So what am I missing? :-)

Well no need to be sarcastic.

You are actually missing the skills to write good code . It doesnt work!!!! Somethings missing.

I'm sorry, I didn't mean to be sarcastic. I apologize. I was just confused.

What's wrong with the code I gave you?

No Problems, i changed it around so the user can check home or away for each row.

How do i insert to DB so that that the users choice for each game(8 games per round) is input into winner field.
database table :

id----user_id--points--round--game----winner---comp_id

144 23 0 1 1 hawthorn 3
145 23 0 1 2 melbourne 3
146 23 0 1 3 Fremantle 3
et etc

The query for inserting is:

INSERT INTO yourtable (user_id, points, round, game, winner, comp_id) VALUES (23, 0, 1, 1, 'hawthorn', 3);

I assume that attribute id is your primary key with AUTO_INCREMENT so it gets its value automatically.
To run the query in PHP:

mysql_query("INSERT .... ");

You have to be connected to the database - see manual entry for mysql_query().

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.