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.
Related
This is my code I just need to add pagination to my code, I try some other example but it failed to work.
In my HTML code I add pagination raw (<<1,2,3,4>>)
its working in Wordpress using a database connection
The URL is like ?eventid=#ID
I checked many codes and example in SO but I failed
function ee_attendee_list($atts){
global $wpdb, $post;
$EVT_ID = $atts['eventid'];
$post = get_post( $EVT_ID );
echo '
';
$sql = "SELECT ATT_fname, ATT_lname, ATT_email, ATT_address, ATT_phone, STA_ID ";
$sql .= "FROM {$wpdb->prefix}esp_attendee_meta ";
$sql .= "INNER JOIN {$wpdb->prefix}esp_registration ";
$sql .= "ON {$wpdb->prefix}esp_attendee_meta.ATT_ID = {$wpdb->prefix}esp_registration.ATT_ID ";
$sql .= "WHERE {$wpdb->prefix}esp_registration.EVT_ID = %d";
$attendees = $wpdb->get_results( $wpdb->prepare( $sql, $post->ID ));
echo '<table class="blueTable">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Address</th>
<th>State</th>
<th>Country</th>
</tr>
</thead>
<tfoot><tr>
<td colspan="6">';
echo '
<div class="links">« <a class="active" href="#">1</a> 2 3 4 »</div>
</td>
</tr>
</tfoot>
<tbody>';
foreach($attendees as $attendee){
$fname = $attendee->ATT_fname;
$lname = $attendee->ATT_lname;
$email = $attendee->ATT_email;
if (empty($attendee->ATT_phone)){ $phone = "No Phone"; } else { $phone = $attendee->ATT_phone; }
if (empty($attendee->ATT_address)){ $address = "No Address"; } else { $address = $attendee->ATT_address; }
$STA_ID = $attendee->STA_ID;
echo "
<tr>
<td>$fname $lname</td>
<td>$email</td>
<td>$phone</td>
<td>$address</td>
<td>$statename</td>
<td>$country</td>
</tr>
";
}
echo "</tbody>
</tr>
</table> ";
}
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);
?>
i am trying to delete some rows but i dont know where i am mistaking please check this below code and suggest my error with solution:
if(isset($_GET['delete']) && $_GET['delete']=="true")
{
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++)
{
echo $checkbox[$i]; // here i am going to write delete query
}
}
Now my HTML code for that. I have created a table for users.
it looks something like this in HTML
<table id="sample_2">
<thead>
<tr>
<th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes" /></th>
<th>Username</th>
<th>Full Name</th>
<th class="hidden-480">Email</th>
<th>Mobile</th>
<th>Activation Key</th>
<th class="hidden-480">Status</th>
</tr>
</thead>
<tbody>
<?php $user_details->all_user_details(); ?>
</tbody>
</table>
Now here is the function i am using. to create table rows. So check this out:
while ($row = $database->fetch_array($result_set)) {
$single_row ="<tr class=\"odd gradeX\">
<td><input type=\"checkbox\" name=\"checkbox[]\" class=\"checkboxes\" value=\"".$row["userid"]."\" /></td>
<td>".$row['username']."</td>
<td>".$row['fullname']."</td>
<td class=\"hidden-480\">".$row['email']."</td>
<td>".$row['mobile']."</td>
<td>".$row['user_activation_key']."</td>";
if($row['status']==1){
$single_row .= "<td><span class=\"label label-success\">Approved</span></td>";
} else{
$single_row .= "<td><span class=\"label label-danger\">Pending</span></td>"; }
$single_row .="</tr>";
echo $single_row;
}
any solution for this problem? I know i am making mistake somewhere in $_POST['checkbox'] while getting the value, Please suggest.
Thank you!
this is your first problem:
if(isset($_GET['delete']) && $_GET['delete']=="true")
{
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++)
{
echo $checkbox[$i]; // here i am going to write delete query
}
}
please change it to this:
if (isset($_GET['delete']))
{
if ($_GET['delete']=="true") {
$checkbox = $_POST['checkbox'];
for($i=0;$i<count($checkbox);$i++)
{
echo $checkbox[$i]; // here i am going to write delete query
}
}
}
and also you forgot to leave a space between if and (
Im writing a function to get the parent and child ids but for the third loop there is a
problem the loop gets even the previous loops id also .
How can i avoid it?
<?
$results = '
<table>
<thead>
<tr >
<td id="ticket" align="center" ><b>Task<br />ID</b></td>
<td id="ticket" align="center" ><b>col1</td>
<td id="ticket" align="center" ><b>col2</td>
</tr>
</thead>
<tbody>';
while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC))
{
$results .='
<tr >
<td align="center">
'.$row['Task_id'].'
</td>';
$results .= '<td align="center">';
$gg = mysqli_query($dbc,"select * from Tasks where ParentTask_Id='".$row['Task_id']."'");
echo "<br>";
while ($rowdd = mysqli_fetch_assoc($gg))
{
$results .= $rowdd['Task_id']."<br><br>";
$gg2 = mysqli_query($dbc,"select * from Tasks where ParentTask_Id='".$rowdd['Task_id']."'");
while ($rowdd2 = mysqli_fetch_assoc($gg2))
{
$results2 = $rowdd2['Task_id']."<br><br>";
}
echo "<br>";
}
// $results .= $car ;
// $results .= $t;
$results .='</td>';
$results .=' <td align="left" >'?>
<?
$results .= $results2;
$results .='</td>';
$results .='
</tr>';
}
?>
Is the $results variable empty? I only see it being concatenated.
Also, on your table you have multiple ids that are the same. You either need to change that to a class or have a unique value for each id.
What I would like to do is number each row in my table. I can't manually number the table myself, as all of the info in it is retrieved from a database. Is this possible with jQuery or PHP? Here's a screen shot of the table:
I tried searching for this, and did not find anything that helped me.
Here is the PHP / HTML that is displaying the table:
<tr>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Created on</th>
<th style="width:65px;">Status</th>
<th>Actions</th>
</tr>
<?php
[...]
//Display the results
while($info = mysql_fetch_assoc($result)){
//data
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
//status
if($isActive == "1") {
$status = "<span class=\"open\">Open</span>";
$status2 = "active";
}
else if($isActive == "0") {
$status = "<span class=\"closed\">Closed</span>";
$status2 = "closed";
}
else {
$status = "";
}
echo "
<tr>
<td style=\"min-width: 87px;\">$name</td>
<td style=\"min-width:248px;\" title=\"$email\">".addEllipsis($email, 33)."</td>
<td title=\"$subject\">".addEllipsis($subject, 18)."</td>
<td style=\"width: 235px;\">$created</td>
<td title=\"This ticket is $status2\">$status</td>
<td><a href='/employee/employee.php?ticket=$ticketid'>View Ticket »</a></td>
</tr>
";
}
As you can see, it's displayed with a while loop.
If anyone knows a way to number each line in my table with jQuery or PHP, please help me :)
$trCounter=0;
while($info = mysql_fetch_assoc($result)){
//data
$name = $info['name'];
$email = $info['email'];
$subject = $info['subject'];
$ticketid = $info['ticket'];
$isActive = $info['is_active'];
$created = $info['created'];
//status
if($isActive == "1") {
$status = "<span class=\"open\">Open</span>";
$status2 = "active";
}
else if($isActive == "0") {
$status = "<span class=\"closed\">Closed</span>";
$status2 = "closed";
}
else {
$status = "";
}
echo "
<tr>
<td>$trCounter++</td>
<td style=\"min-width: 87px;\">$name</td>
<td style=\"min-width:248px;\" title=\"$email\">".addEllipsis($email, 33)."</td>
<td title=\"$subject\">".addEllipsis($subject, 18)."</td>
<td style=\"width: 235px;\">$created</td>
<td title=\"This ticket is $status2\">$status</td>
<td><a href='/employee/employee.php?ticket=$ticketid'>View Ticket »</a></td>
</tr>
";
}
or you could always use the :eq api in your jquery selector or its equivalent to work with the index but like I asked it depends on what you want to do with the index.
I would go with PHP solution listed by Atul Gupta.
To add more - you also can to start iteration based on which page you are.
<?php
$i = ($page-1) * $itemsPerPage;
while(....)
{
echo $i;
$i++;
}
?>
if you are on the second page of your list would get something like 11,12,13,14,....
jQuery:
$(function () {
var i = 0;
$('table thead tr').prepend('<th>#</th>');
$('table tbody tr').each(function () {
i += 1;
$(this).prepend('<td>' + i + '</td>');
});
});
PHP
<tr>
<th>Sr. No</th> // Add header for counter
<th>Name</th>
...
</tr>
...
$i=1; // add counter -----------corrected-------------
while($info = mysql_fetch_assoc($result)){
//data
...
echo "
<tr>
<td>$i</td> // include counter to table
<td style=\"min-width: 87px;\">$name</td>
...
</tr>
";
$i++; // increment counter
}
Set an auto increment property in the SQL table, which can be used as an index, and will increase automatically when a new entry is added?