Jump to content

how to turn this array into a form


bigmark

Recommended Posts

I have a script (below) that consists of a form using javascript that shows an array in a table below it.

What i would like to know is can i turn this into a form 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['game'] . "</td>";

echo "<td width='150'>" . $row['home'] . "</td>";

echo "<td width='150'>" . $row['away'] . "</td>";

echo "</form>";

echo "</tr>";

}

 

echo "</table>";

 

 

mysql_close($con);

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/96089-how-to-turn-this-array-into-a-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.