I have php file that generate result from user input. The result are not equals. I mean sometimes it generate 3 result and sometimes it generate 5 or 4 or 2 result. First, I define an array variable to store these result:
$resultcount = 0;
$result=array();
while(!feof($fpout3))
{
$row = fgets($fpout3);
if (!$row) {continue;}
$element = preg_split("/\t/", $row);
$page = $element[0];
$queryName = $element[1];
$target_name = $element[7];
$var_target = $page."\t".$element[1]."\t".$element[2];
if(count($element) != 1)
{
if($i < 10)
{
echo "<tr align='center'><td align=left><input type='checkbox' id='checkedSeq' name='target[]' value='$var_target'>$target_name</td></tr>";
fwrite($fp, "$var_target\n");
// fill $result array
$resultcount++;
$result[$resultcount]=$target_name;
//////////////////////
}
}
}
I want to send the $result array with url link to save it in the database: I already send other variables with the url and now want to pass the $result array with them:
echo "<form action='saveResult.php?searchType=$searchType&querySeq=$querySeq&patientIDarray=$patientIDarray&expect=$expect&wordSize=$wordSize' method='post' target='_blank' onsubmit=\"return checkform(this);\">";
echo "<input type='submit' value='Save Result'>";
echo "</form>";
saveResult.php:
<?php
$searchType = (empty($_GET['searchType'])) ? '' : $_GET['searchType'];
$querySeq = (empty($_GET['querySeq'])) ? '' : $_GET['querySeq'];
$patientIDarray = (empty($_GET['patientIDarray'])) ? '' : $_GET['patientIDarray'];
$QueryDate = date("Y-m-d");
$expect=(empty($_GET['expect'])) ? 10 : $_GET['expect'];
$wordSize = (empty($_GET['wordSize'])) ? '' : $_GET['wordSize'];
$serverName = "Alaa";
$connectionInfo = array( "Database"=>"i2b2blast", "UID"=>"i2b2blast", "PWD"=>"demouser");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Result Saved.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$sql = "INSERT INTO BlastQueryDim (QuerySeq, DatabaseName, WordSize, ExpectThreshold, QueryDate) VALUES ('$querySeq', '$patientIDarray', '$wordSize', '$expect', '$QueryDate')";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
echo "<script>
alert('Result Saved');
</script>";
?>
My question: How to pass $result array with the url? and how to get each index in the other php "saveResult"?
Thanks,
Edit1:
I type:
echo "<form action='saveResult.php?searchType=$searchType&querySeq=$querySeq&patientIDarray=$patientIDarray&expect=$expect&wordSize=$wordSize' method='post' target='_blank' onsubmit=\"return checkform(this);\">";
foreach ($result as $resultcount => $target_name)
echo "<input type='hidden' name='result[$resultcount]' value='$target_name'/>";
echo "<input type='submit' value='Save Result'>";
echo "</form>";
in saveResult.php, i type:
$result = empty($_POST['result']) ? array() : $_POST['result'];
and try to echo it and it displays: 'Array' which means that it recieve it as an empty!
Edit 2: I solve the problem by using:
$result = json_encode($_POST['result'], true);
echo $result;
Now, the output of echo is:
{"1":"gi|1786181|gb|AE000111|ECAE000111","2":"gi|1786250|gb|AE000117|ECAE000117"}
How can I insert the second cell of each row in the database? I want to insert 'gi|1786181|gb|AE000111|ECAE000111' in a row and insert 'gi|1786250|gb|AE000117|ECAE000117' in another row