Random selection of dynamic check boxes - php

I am working on building a small php file. I need to select random check boxes. check boxes dynamic as they are pulled from a table with some conditions.
Please let me know if i can randomly select few check boxes say if i get 100 results from the mysql table, 10 random check box needs to be selected.
<?php
$n1=0;
$rambo = strip_tags(#$_POST["assoocc"]);
$r11 = strip_tags(#$_POST["ccdate"]);
$r12 = strip_tags(#$_POST["rrdate"]);
$submit = #$_POST["submit22"];
?>
<body><div>
<form action="selectedcc.php" method="post">
<center> <table width="600" border="1" cellpadding="1" cellspacing="1">
<tr>
<th colspan="3"> Total cases for QA</th>
<th colspan="2"><?php
$ticket=mysql_query("SELECT * FROM us_tickets where (status='Resolved') and (associate='$rambo') and (resolve_date >='$r11') and (resolve_date <='$r12')");
$m1=mysql_num_rows($ticket);
echo "$m1";
?></th>
<th colspan="2"><select name="assoocc1" class="form-control" id="sel1" style="width: 150px;" >
<?php echo "<option value=$rambo selected>".$rambo."</option>";
?>
</select></th>
<th colspan="1"><input type="submit" name="sub" value="Submit For QA "/></th>
</tr>
<tr>
<th>Select Here</th>
<th>Case Id</th>
<th>Task</th>
<th>Number of ASINs</th>
<th>SLA Details</th>
<th>Create date</th>
<th>Resolved date</th>
<th>Rootcause</th></tr>
<?php
if ($submit)
{
if ($rambo&&$r11&&$r12)
{
if ($r11<$r12)
{
$ticket=mysql_query("SELECT * FROM us_tickets where (status='Resolved') and (associate='$rambo') and (resolve_date >='$r11') and (resolve_date <='$r12')");
$m1=mysql_num_rows($ticket);
for($k=0; $k<$m1; $k++)
{
$caseid1 = $task1 = $asin1 = $sla1 = $associate1 = $quer = "";
${"caseid".$k}=mysql_result($ticket,$k, "case_id");
${"task".$k}=mysql_result($ticket,$k, "sub_issue");
${"asin".$k}=mysql_result($ticket,$k, "asin");
${"vendor_credit".$k}=mysql_result($ticket,$k, "vendor_credit");
${"create_date".$k}=mysql_result($ticket,$k, "create_date");
${"resolve_date".$k}=mysql_result($ticket,$k, "resolve_date");
${"root_cause".$k}=mysql_result($ticket,$k, "root_cause");
${"associate".$k}=mysql_result($ticket,$k, "associate");
echo "<tr>"."<th>"."<input type='checkbox' value='${'caseid'.$k}' name='checkboxvar[]'>"."</th>"."<th>".${'caseid'.$k}."</th>"."<th>".${'task'.$k}."</th>"."<th>".${'asin'.$k}."</th>"."<th>".${'vendor_credit'.$k}."</th>"."<th>".${'create_date'.$k}."</th>"."<th>".${'resolve_date'.$k}."</th>"."<th>".${'root_cause'.$k}."</th>"."</tr>";
}
}
else
{
echo "<script>alert('Error:START DATE should be less than END DATE. Go back to QA Home page and enter all fields')</script>";
}
}
else
{
echo "<script>alert('Error:Go back to QA Home page and enter all fields')</script>";
}
}
?>
</table></center></form></div></body></html>

Took the random function UniqueRandomNumbersWithinRange from Generating UNIQUE Random Numbers within a range - PHP
<?php
function UniqueRandomNumbersWithinRange($min, $max, $quantity) {
$numbers = range($min, $max);
shuffle($numbers);
$arr = array_slice($numbers, 0, $quantity);
sort($arr);
return $arr;
}
$chkArr = array();
$rand = UniqueRandomNumbersWithinRange(0, 100, 10);
$rIdx = 0;
for($k=0; $k<100; $k++){
$caseid1 = $task1 = $asin1 = $sla1 = $associate1 = $quer = "";
${"caseid".$k}=mysql_result($ticket,$k, "case_id");
${"task".$k}=mysql_result($ticket,$k, "sub_issue");
${"asin".$k}=mysql_result($ticket,$k, "asin");
${"vendor_credit".$k}=mysql_result($ticket,$k, "vendor_credit");
${"create_date".$k}=mysql_result($ticket,$k, "create_date");
${"resolve_date".$k}=mysql_result($ticket,$k, "resolve_date");
${"root_cause".$k}=mysql_result($ticket,$k, "root_cause");
${"associate".$k}=mysql_result($ticket,$k, "associate");
$chk = '';
if( in_array($k, $rand) )
$chk = "checked";
array_push($chkArr, "<tr>"."<th>"."<input type='checkbox' ".$chk ." value='${'caseid'.$k}' name='checkboxvar[]'>"."</th>"."<th>".${'caseid'.$k}."</th>"."<th>".${'task'.$k}."</th>"."<th>".${'asin'.$k}."</th>"."<th>".${'vendor_credit'.$k}."</th>"."<th>".${'create_date'.$k}."</th>"."<th>".${'resolve_date'.$k}."</th>"."<th>".${'root_cause'.$k}."</th>"."</tr>");
}
echo implode($chkArr);
?>

Related

PHP - Extract Line by line in Sprintf output

I have a CSV file, that I am using to populate a table - that works fine. The table is an inquiry form, so users can select the item(s) they want more information on and submit an email.
In this email I need to include the item details. So far I am only able to get the value of "1" field within the row to submit.
In my searches I found a way to get the needed fields from the rows into a line, but I cannot seem to figure out how to get each line individually to use as the value of the check box.
Here is my code:
$file = fopen('myfile.csv', 'r');
$fields = array();
if ($file) {
while (($data = fgetcsv($file)) !== false) {
if(empty($fields)) {
$fields = $data;
continue;
}
$row = array_combine($fields, $data);
$output = sprintf("%s - %s - %u <br />\n",
$row['make'],
$row['model'],
$row['serial']);
echo $output;
}
fclose($file);
}
This creates a list like ...
Tanglewood - TW66 - 311592807
MICHAEL KELLY - MKDF4FL - 311595895
Epiphone - DR500MCE - 311599764
ALVAREZ - MD70CE - 311603486
FENDER - *CD220SCE ASH BURL - 311606198
Which is perfect ... but in the table I have the check box to select for inquiry. That check box needs to have the value of that line only, so I need to count the number of rows, and then grab 1 line for whichever number row we are on.
Something like echo $output[3]; would give me
Epiphone - DR500MCE - 311599764
EDIT ---
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<table class="tablesaw" data-tablesaw-sortable data-tablesaw-sortable-switch>
<thead>
<tr>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2"></th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Make</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">Model</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">Serial</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="3">RPD</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="4">Retail</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="5">Net Price</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="6">Photo</th>
</tr>
</thead>
<tbody>
<?php
$file = fopen('file.csv', 'r');
$fields = array();
if($file)
{
while(($data=fgetcsv($file, ',')) !== false)
{
if(empty($fields))
{
$fields = $data;
continue;
}
$row = array_combine($fields, $data);
$output[] = sprintf("%s - %s - %u <br />\n", $row['make'], $row['model'], $row['serial']);
}
fclose($file);
}
for($x=0; $x < count($output); $x++)
{
// Build lines of checkbox rows here
echo($output[$x]);
}
?>
<?php
$f = fopen("file.csv", "r");
$columns1 = array(1);
$columns2 = array(2,3,4,5,6);
$columns3 = array(7);
$flag = true;
while (($line = fgetcsv($f)) !== false) {
if($flag) { $flag = false; continue; }
echo "<tr>";
foreach ($line as $index=>$val) {
if (in_array($index+1, $columns1)) {
echo("\t<td><input type='checkbox' name='checkboxvar[]' value='$val'></td>\r\n");
}
if (in_array($index+1, $columns1)) {
echo("\t<td>$val</td>\r\n");
}
if (in_array($index+1, $columns2)) {
echo("\t<td>$val</td>\r\n");
}
if (in_array($index+1, $columns3)) {
if($val == "0"){
echo("\t<td></td>\r\n");
} else {
echo("\t<td><a class=' wpex-lightbox' href='http://mirc.pixelcraftstudio.net/wp-content/uploads/mirc_inv_pics/$val.jpg' target='_self' data-type='image'><img style='width:24px; height:24px; margin-top:8px;' src='http://mirc.pixelcraftstudio.net/wp-content/themes/mirc-child/tablesaw/icon-instagram.jpg'/></a></td>\r\n");
}
}
}
echo "</tr>\n";
}
fclose($f);
?>
</tbody>
</table>
<input style="position:fixed; bottom:0px; left:50%; font-size:16px; margin- left:-155px;" name="submit" type="submit" value="Contact Us About Your Selected Items" />
</form>
I think you need to create an array, currently your code doesn't do this. Try changing this line:
$output = sprintf("%s - %s - %u <br />\n", $row['make'], $row['model'], $row['serial']);
to:
$output[] = sprintf("%s - %s - %u <br />\n",$row['make'], $row['model'], $row['serial']);
Now:
echo $output[3];, etc should contain your data.
You may have to build the array like this instead:
$output[] = array("make"=>"$row['make']", "model"=>"$row['model']", "serial"=>"$row['serial']");
Now:
echo $output[3]['make'];, etc should contain your 'make' data, repeat for each array element ('model' and 'serial').
EDIT - New Code
I did not address your table building needs. All I did was get the data into the format you requested. I had several problems with your original code, it did not run as you posted it. $fields contained 7 elements while $data contained 6 elements. For this reason array_combine() failed. I had to add 'null' to the last element of the csv file. I loaded your sample data into Excel and created a csv file from it. Also, the keys are case sensitive, so $row['make'] had to became $row['Make'], .... etc. Arrays are 0 based so echo($output[2]) will output Epiphone - DR500MCE - 311599764. I hope this meets your needs.
$file = fopen('inventory.csv', 'r');
$fields = array();
if($file)
{
while(($data=fgetcsv($file, ',')) !== false)
{
if(empty($fields))
{
$fields = $data;
continue;
}
$row = array_combine($fields, $data);
$output[] = sprintf("%s - %s - %u <br />\n", $row['Make'], $row['Model'], $row['Serial']);
}
fclose($file);
foreach($output as $key=>$value)
{
// Build lines of checkbox rows here
echo($key . ': '. $value);
}
}
Edit - Addition
That's easy, use a for loop instead of a foreach loop, like this:
for($x=0; $x < count($output); $x++)
{
// Build lines of checkbox rows here
echo($output[$x]);
}
This way you can also change the id attribute of each checkbox by adding the number value to the id.
EDIT - Last
This is a complete web page, it builds the table as the csv page you posted before and it puts the value you wanted in the checkbox. The only thing you should do to make life simple is update your Excel file to include the Photo path/name. BE SURE to include the opening and closing img tags in that field and you should be good to go.
<!DOCTYPE HTML>
<html>
<head>
<title>Sample Table</title>
</head>
<body>
<form action="<?php echo $_SERVER['REQUEST_URI'] ?>" method="post">
<table class="tablesaw" data-tablesaw-sortable data-tablesaw-sortable-switch>
<thead>
<tr>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">Select</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="persist">Make</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="1">Model</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="2">Serial</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="3">RPD</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="4">Retail</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="5">Net Price</th>
<th scope="col" data-tablesaw-sortable-col data-tablesaw-priority="6">Photo</th>
</tr>
</thead>
<tbody>
<?php
$file = fopen('inventory.csv', 'r');
$fields = array();
if($file)
{
while(($data=fgetcsv($file, ',')) !== false)
{
if(empty($fields))
{
$fields = $data;
continue;
}
$output[] = array_combine($fields, $data);
}
fclose($file);
foreach($output as $main)
{
echo(' <tr>' . PHP_EOL);
echo(" <td><input type='checkbox' name='checkboxvar[]' value='{$main['Make']} - {$main['Model']} - {$main['Serial']}'></td>");
foreach($main as $key=>$value)
{
echo("<td>$value</td>");
}
echo(PHP_EOL . ' </tr>' . PHP_EOL);
}
}
?>
</tbody>
</table>
<br>
<input style="position: fixed; bottom: 0px; left: 50%; font-size: 16px; margin-left: -155px;" name="submit" type="submit" value="Contact Us About Your Selected Items">
</form>
</body>
</html>
Here is the code Im using to generate the table.
<?php
$f = fopen("file.csv", "r");
$columns1 = array(1);
$columns2 = array(2,3,4,5,6);
$columns3 = array(7);
$flag = true;
while (($line = fgetcsv($f)) !== false) {
if($flag) { $flag = false; continue; }
echo "<tr>";
foreach ($line as $index=>$val) {
if (in_array($index+1, $columns1)) {
echo("\t<td><input type='checkbox' name='checkboxvar[]' value='$val'> </td>\r\n");
}
if (in_array($index+1, $columns1)) {
echo("\t<td>$val</td>\r\n");
}
if (in_array($index+1, $columns2)) {
echo("\t<td>$val</td>\r\n");
}
if (in_array($index+1, $columns3)) {
if($val == "0"){
echo("\t<td></td>\r\n");
} else {
echo("\t<td><a class=' wpex-lightbox' href='http://mirc.pixelcraftstudio.net/wp-content/uploads/mirc_inv_pics/$val.jpg' target='_self' data-type='image'><img style='width:24px; height:24px; margin-top:8px;' src='http://mirc.pixelcraftstudio.net/wp-content/themes/mirc-child/tablesaw/icon-instagram.jpg'/></a></td>\r\n");
}
}
}
echo "</tr>\n";
}
fclose($f);
?>
So the first column I have the checkbox, and can get that tho show the value of the first column. But I need the value for columns 1,2 and 3 to be included in the checkbox.
Maybe my method of thinking with getting the 3 items first is not the best approach?
The 7th column is only split because its an image and needs a preview icon

How can I optimise and improve the speed of this MySQL query?

I am trying to get information from my database and display it. Here is a screenshot of what the page looks like:
The page loads really slow
Is there any way to make it load and display the data faster?
Here is the code.
<table align="center" class="pTable">
<tr class="main"> <th class="pTableHeader"> ID </th> <th class="pTableHeader"> Room </th> <th class="pTableHeader"> Status</th> </tr>
<?php
gc_enable();
gc_collect_cycles();
flush();
$this->mysql = new sqli('HIDDEN','HIDDEN','HIDDEN','HIDDEN');
$bots = $this->mysql->fetch_array("SELECT `pid`,`room`,`id` from `bots`;");
foreach ($bots as $b) {
if(is_numeric($b["room"])) {
$xat = file_get_contents('http://www.xat.com/xat'.trim($b["room"]));
$name = sp($xat, '<h1> ', '</h1>');
}
else $name = $b['room'];
//$b["pid"] = isset($b["pid"])?$b["pid"]:false;
//$online = \"start.php {$b['id']} {$b['id']}\"", $output) && count($output) > 1 ? true : false;
$online = file_exists("/proc/{$b['pid']}" )?true:false;
if($online === true) $status = "<font color='green'>Online</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/online.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
else $status = "<font color='red'>Offline</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/offline.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
if($b["room"] === '') {
$name = "No Room";
$status = "<font color='red'>Not Setup!</font> <div style='float:right'><img src='http://fexbots.com/Images/Pawns/hang.png'> <a href='/botinfo?botid={$b["id"]}'>More info</a></div>";
echo '<tr> <td> '.$b["id"].' </td> <td> No Room <td> '.$status.'</td> </tr>';
}
else echo "<tr> <td> ".$b['id']." </td> <td> <a href='http://www.xat.com/$name'>$name</a> <td> ".$status."</td> </tr>";
}
function sp($content, $start, $end, $lower=false) {
if($lower!=false) {
$content = strtolower($content);
$start = strtolower($start);
$end = strtolower($end);
}
$content = substr($content, strpos($content,$start)+strlen($start));
$content = substr($content, 0, strpos($content,$end));
return $content;
}
?>
</table>
You seem to download the content from an URL inside the loop. Maybe that is the cause to why it is slow and not the mysql query itself.
Try to write out some timestamps or comment some code out to see what is causing it to be slow.

Is it possible to display the result of a mysql query without looping in php?

Is it possible to use an array holding the result of a mysql query and displaying it by incrementing the array index counter?
I have this code that allows a number input from 6 to 11 and generates
2 tables dividing the number equally if possible.It generates
incremented team names (ex. team 1, team2, ...). I tried using a loop
in displaying the real team names from my database but it loops the
generation of tables also and creates so many tables.please help.
<?php
$count = count($result);
$team = $count;
$teamctr = 1;
if ($team > 5 && $team <= 11){
$table = 2;
$tblctr = 1;
$r1ctr = 0;
$r2ctr = 0;
if ($team == 6){
$row1 = 3;
$row2 = 3;
}
else if ($team == 7){
$row1 = 3;
$row2 = 4;
}
else if ($team == 8){
$row1 = 4;
$row2 = 4;
}
else if ($team == 9){
$row1 = 4;
$row2 = 5;
}
else if ($team == 10){
$row1 = 5;
$row2 = 5;
}
else if ($team == 11){
$row1 = 5;
$row2 = 6;
}
while($tblctr <= $table){$i = 0;
echo "Number of Teams: ".$team; ?><br><?php
echo "Group Into: ".$table; ?><br><?php
?>
<table border="1" align="center" width="30%">
<tr>
<th width="80%" align="center">Group &nbsp <?php echo $tblctr; ?></th>
<th width="10%" align="center">W</th>
<th width="10%" align="center">L</th>
</tr>
<?php
if($tblctr = 1){
while($r1ctr < $row1){
?>
<tr>
<td>Team &nbsp <?php echo $teamctr ?></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<?php
$r1ctr++;
$teamctr++;
}
echo ""; ?><br><?php
}
if($tblctr = 2){
?>
<table border="1" align="center" width="30%">
<tr>
<th width="80%" align="center">Group &nbsp <?php echo $tblctr; ?></th>
<th width="10%" align="center">W</th>
<th width="10%" align="center">L</th>
</tr>
<?php
while($r2ctr < $row2){
?>
<tr>
<td>Team &nbsp <?php echo $teamctr ?></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<td><input type="text" name="score" maxlength="6" size="6" /></td>
<?php
$r2ctr++;
$teamctr++;
}
echo ""; ?><br><?php
}
else{
echo "Done IF";
}
$tblctr++;
}
}
How can I use this query to display the team name from my database?
$query = "SELECT * From tbl_teams";
$result = mysql_query($query);
if($result) {
$i = 0;
while ($row = mysql_fetch_array($result)) {
$id[$i] = $row['team_name'];
echo $id[$i];
}
}
In your database query loop, try changing to
$team_names = array();
while ($row = mysql_fetch_array($result)) {
$team_names[] = $row['team_name'];
}
Then in your table code, try changing it to
$count = count($team_names);
$team = $count;
$teamctr = 0;
and
<td>Team &nbsp <?php echo $team_names[$teamctr]; ?></td>

It is only showing one value for each row

I have a phpfiddle here: http://phpfiddle.org/main/code/get-rps
The problem I am getting is that in the Total Marks column, it is only display the total marks for the last question in all of the rows for all questions, rather than looping through all the total marks and displaying the correct total marks for each question. What am I doing wrong in the code?
Below is code:
<?php
$incorrect_ans = array(
array('A','C','D'),
array('B','C','D'),
array('A','B','D'),
array('A','B','C'));
$searchQuestionNo = array(
1,
2,
2,
3);
$totalMarks = array(
3,
5,
5,
2);
$ques_ans = array(); //to store incorrect answers against ques no.
$q_occ_count = array_count_values($searchQuestionNo);
foreach($searchQuestionNo as $key => $questionNo)
{
if ( ! array_key_exists($questionNo, $ques_ans))
{
if($q_occ_count[$questionNo] === 1) //if a ques has only one correct ans
{
$ques_ans[$questionNo] = $incorrect_ans[$key]; //store the array of incorrect ans against the ques no as key
}
else //if a ques has more than 1 correct ans
{
//find the intersection of incorrect_ans arrays for this ques
$q_keys = array_keys($searchQuestionNo, $questionNo);
$q_incorrect_ans = $incorrect_ans[$q_keys[0]];
foreach($q_keys as $q_key) {
$q_incorrect_ans = array_values(array_intersect($q_incorrect_ans, $incorrect_ans[$q_key]));
}
$ques_ans[$questionNo] = $q_incorrect_ans; //store the array of incorrect ans against the ques no as key
}
}
}
?>
<table border='1' id='penaltytbl'>
<thead>
<tr>
<th class='questionnoth'>Question No.</th>
<th class='answerth'>Incorrect Answer</th>
<th class='marksth'>Total Marks</th>
</tr>
</thead>
<tbody>
<?php
foreach($ques_ans as $questionNo => $inc_ans)
{
$q_row_span = count($inc_ans);
$row_count = 0;
?>
<tr class="questiontd">
<!-- Question No -->
<td class="questionnumtd q<?php echo $questionNo?>_qnum" rowspan="<?php echo $q_row_span ?>">
<?php echo $questionNo?><input type="hidden" name="numQuestion" value="<?php echo $questionNo?>" />
</td>
<!-- first incorrect ans -->
<td class="answertd"><?php echo $inc_ans[$row_count]; ?></td>
<!-- Marks -->
<td class="totalmarkstd" rowspan="<?php echo$q_row_span?>"><?php echo$totalMarks[$key]?></td>
</tr>
<?php
//remaining incorrect answers in separate row (if any) follows here
if($row_count < $q_row_span - 1)
{
for($i=($row_count + 1); $i<$q_row_span; $i++) { ?>
<tr><td class="answertd"><?php echo $inc_ans[$i]; ?></td></tr>
<?php
}
}
}
?>
</tbody>
</table>
This line is your problem.
<?php echo$totalMarks[$key]?>
$key is set from your loop above, and is never reset in the bottom loop, so it is still has the last value from that loop. I'm assuming it should be <?php echo$totalMarks[$questionNo]?>

PHP Search Code from HTML form

I had a previous question on here a few minutes ago about a syntax error that was sorted. I need help getting this script working or at least for someone to point me in the right direction.
This is a search script to search by multiple fields. The search() array works fine and is a series of tickboxes with the following code:
<td width="22"><input type="checkbox" name="search[olevel = 'Yes']" id="search[olevel = 'Yes']" value="1"/>
The postcode box is a text box with the following code:
<input name="postcode[]" type="text" id="postcode[]" size="12" maxlength="12" /></td>
When I tick the olevel box it returns all the records that have Yes in the olevel field. That works as I expect.
If I put in anything in the postcode box it returns no results.
Here is the php code for the search engine.
<?php
include ('c1.php');
if ($_COOKIE["auth"] == "1") {
$display_block = "<p>You are an authorized user.</p>";
} else {
header("Location: userlogin.html");
exit;
}
doDB();
$display_block = "<h1>Results</h1>";
if (isset($_POST['search']) && !empty($_POST['search'])) {
foreach ($_POST['search'] as $key => $value) {
if ($value == 1)
$search[] = "$key";
$searchstring = implode(' AND ', $search);
$post_map = array(
'postcode' => 'candididate_contact_details.postcode'
);
}
if (isset($_POST['postcode']) && !empty($_POST['postcode'])) {
foreach ($_POST['postcode'] as $key => $value) {
if (array_key_exists($key, $post_map))
$search[] = $post_map[$key] . '=' . mysql_real_escape_string($value);
echo $searchstring;
echo $search;
$query = "SELECT candidate_id.master_id, candidate_contact_details.first_name, candidate_contact_details.last_name, candidate_contact_details.home_phone, candidate_contact_details.work_phone, candidate_contact_details.mobile_phone, candidate_contact_details.email FROM candidate_id, candidate_contact_details, qualifications, security_experience, previous_career WHERE qualifications.active = 'finished' and candidate_id.master_id = candidate_contact_details.master_id and candidate_id.master_id = qualifications.master_id and candidate_id.master_id = security_experience.master_id and candidate_id.master_id = previous_career.master_id and $searchstring";
$query_res = mysqli_query($mysqli, $query)
or die(mysqli_error($mysqli));
// $search = mysqli_query($mysqli, $query)or die(mysqli_error($mysqli));
{
$display_block .= "
<table width=\"98%\" cellspacing=\"2\" border=\"1\">
<tr>
<th>Registration Number</th>
<th>First Name</th>
<th>Last Name</th>
<th>Home Number</th>
<th>Work Number</th>
<th>Mobile Number</th>
<th>E-Mail</th>
</tr>";
while ($result = mysqli_fetch_array($query_res)) {
$regnum = $result['master_id'];
$first_name = $result['first_name'];
$last_name = $result['last_name'];
$home_phone = $result['home_phone'];
$work_phone = $result['work_phone'];
$mobile_phone = $result['mobile_phone'];
$email = $result['email'];
$display_block .= "
<tr>
<td align=\"center\">$regnum <br></td>
<td align=\"center\">$first_name <br></td>
<td align=\"center\">$last_name <br></td>
<td align=\"center\">$home_phone <br></td>
<td align=\"center\">$work_phone <br></td>
<td align=\"center\">$mobile_phone <br></td>
<td align=\"center\">$email <br></td>
</tr>";
}
$display_block .= "</table>";
}
}
}
}
?>
<html>
<head>
<title> Display results</title>
</head>
<body>
<?php echo $display_block; ?>
</body>
</html>
I know I am doing something wrong but cannot quite figure it out. Thanks in advance.
if I understand correctly, you have several postcodes per form.
then id="postcode[]" is wrong as there will be several id named the same in dom.
just delete that from your code.

Categories