I'm trying to make a filter option using a select dropdown box and I don't know where I am failing. I have a search bar that works perfectly but I want to able to select the location where I would like to search .
For example I can type the name of the job I'm looking for but I would like to filter the locations to only view in one city
Here is my code
Edit : Thanks to ADyson I made some edits to the code I will post the new code over the last one
<?php
require 'views/header.php';
$connection = getDbConntection();
// Search //
if (!empty($_GET['search'])) {
$data = [
'job_name' => '%' . $_GET['search'] . '%',
'location_id' => $_GET['location_id']
];
$searches = $connection->prepare("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id "
. "where jobs.name like :job_name"
. 'AND location_id = :location_id');
$searches->execute($data);
$searches= $query->fetchAll();
// List //
} else {
$query = $connection->query("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id ");
$searches = $query->fetchAll();
}
?>
<div class="w3-row-padding w3-padding-64 w3-container">
<div class="w3-content">
<h1 class="center"> Jobs table </h1>
<br>
<form style="text-align:center" action="index.php" method="GET">
<input type="text" name="search" value="Search jobs..." onfocus="this.value = ''" class="btn btn-danger">
<select name="location_id" class="btn btn-danger">
<?php foreach ($searches as $location): ?>
<?php $selectedText = ($location['id']) ?>
<option value= <?= $selectedText ?> > <?= $location['location_name'] ?></option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search" class="btn btn-danger">
Back to list
</form>
<br>
<div class="center">
<table>
<tr>
<th>ID</th>
<th> Job Name</th>
<th> Job Location</th>
<th> Job Domain</th>
<th> Job Description</th>
<th> Job Salary</th>
<th>Actions</th>
</tr>
<?php foreach ($searches as $key => $job_name) : ?>
<tr>
<th><?= $job_name['id'] ?></th>
<th style="background-color: lightskyblue"><?= $job_name['job_name'] ?></th>
<td><?= $job_name['location_name'] ?></td>
<td><?= $job_name['domain_name'] ?></td>
<td><?= $job_name['description'] ?></td>
<td><?= $job_name['job_salary'] ?></td>
<td> <a class="btn btn-success" href="edit.php?id=<?= $job_name['id'] ?>"> Edit </a>
<a class="btn btn-danger" href="delete.php?id=<?= $job_name['id'] ?>">Delete</a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<style>
table td, table th {
padding: 15px;
text-align: center;
}
table th {
background:#3390FF;
}
table {
width: 100%;
border: 3px solid #ccc;
border-collapse: collapse;
}
.ce
nter {
margin: auto;
width: 100%;
border: 3px solid red;
padding: 10px;
text-align: center;
}
</style>
</div>
</div>
Sorry for the messy code, I'm new to coding in general
Thanks to ADysom I solved the problem , here is the correct code
<?php
require 'views/header.php';
$connection = getDbConntection();
$locations = $connection->query("select * from locations");
// Search //
if (!empty($_GET['search'])) {
$data = [
'job_name' => '%' . $_GET['search'] . '%',
'location_id' => $_GET['location_id']
];
$query = $connection->prepare("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id "
. "where jobs.name like :job_name "
. "AND location_id = :location_id ");
$query->execute($data);
$query = $query->fetchAll();
// print_r($_GET);
// List //
} else {
$query = $connection->query("select jobs.id, jobs.name as job_name, salary as job_salary, description, location_id, domain_id , locations.name as location_name , domains.name as domain_name from jobs
LEFT JOIN locations ON jobs.location_id = locations.id
LEFT JOIN domains on jobs.domain_id = domains.id ");
$query = $query->fetchAll();
}
?>
<div class="w3-row-padding w3-padding-64 w3-container">
<div class="w3-content">
<h1 class="center"> Jobs table </h1>
<br>
<form style="text-align:center" action="index.php" method="GET">
<input type="text" placeholder='Search jobs..' name="search" onfocus="this.value = ''" class="btn btn-danger">
<select name="location_id" class="btn btn-danger">
<?php foreach ($locations as $location): ?>
<option value="<?= $location['id'] ?>">
<?= $location['name'] ?>
</option>
<?php endforeach; ?>
</select>
<input type="submit" value="Search" class="btn btn-danger">
Back to list
</form>
<br>
<div class="center">
<table>
<tr>
<th>ID</th>
<th> Job Name</th>
<th> Job Location</th>
<th> Job Domain</th>
<th> Job Description</th>
<th> Job Salary</th>
<th>Actions</th>
</tr>
<?php foreach ($query as $key => $job_name) : ?>
<tr>
<th><?= $job_name['id'] ?></th>
<th style="background-color: lightskyblue"><?= $job_name['job_name'] ?></th>
<td><?= $job_name['location_name'] ?></td>
<td><?= $job_name['domain_name'] ?></td>
<td><?= $job_name['description'] ?></td>
<td><?= $job_name['job_salary'] ?></td>
<td> <a class="btn btn-success" href="edit.php?id=<?= $job_name['id'] ?>"> Edit </a>
<a class="btn btn-danger" href="delete.php?id=<?= $job_name['id'] ?>">Delete</a> </td>
</tr>
<?php endforeach; ?>
</table>
</div>
<style>
table td, table th {
padding: 15px;
text-align: center;
}
table th {
background:#3390FF;
}
table {
width: 100%;
border: 3px solid #ccc;
border-collapse: collapse;
}
.center {
margin: auto;
width: 100%;
border: 3px solid red;
padding: 10px;
text-align: center;
}
::placeholder {
color: white;
opacity: 1;
}
</style>
</div>
</div>
Related
Sooo I've been working on a site for a friend of my dads so he can keep his business in check etc. I've been using the While Loop to print out a table of the 'Tasks' that can be inputted in to the site, however when I go to change the status of the task it's not doing so?
I'm sure that is the way I'm getting the ID for locating the record that needs to be updated, but I think I'm on the correct lines. So firstly, is there anything obvious other than my shoddy coding? Secondly, this there any better way of getting the ID or the reasoning for the lack of updating? Much Obliged!
HTML - The page
<table class="tasktable">
<tr>
<th style="text-align: center; width: 100px ">Job Number (ID)</th>
<th style="text-align: center; width: 100px">VRM</th>
<th style="text-align: center; width: 175px;">Date Arrived</th>
<th style="text-align: center;">Work</th>
<th style="text-align: center; width:200px;">Customer</th>
<th style="text-align: center; width: 250px;">Task Progress</th>
</tr>
<?php
include 'Login-System/db.php';
$query = 'SELECT * FROM outstanding WHERE taskprogress = "New" OR taskprogress = "In Progress" ORDER by id ASC';
$result = mysqli_query($conn, $query);
if($result):
if(mysqli_num_rows($result)>0):
while($tasks = mysqli_fetch_assoc($result)):
?>
<tr>
<td style="text-align: center;"><h4 name="jobnumberid"><?php echo $tasks['id'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['VRM'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['datearrived'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['work'];?></h4></td>
<td style="text-align: center;"><h4><?php echo $tasks['customer'];?></h4></td>
<td>
<form action="SQL/taskchange.php" role="form" method="post" id="taskchange">
<select name="taskchanger" id="taskchanger" style="margin-top:6px;
width: 150px; float:left" class="form-control">
<option value="#"><?php echo $tasks['taskprogress'];?></option>
<?php
if ($tasks['taskprogress']== "New") {
echo '<option value="In Progress" class="form-control">In Progress</option>
<option value="Complete" class="form-control">Complete</option>';
} else { if ($tasks['taskprogress']== "In Progress") {
echo '<option value="New" class="form-control">New</option>
<option value="Complete" class="form-control">Complete</option>';
} else {
echo '<option value="New" class="form-control">New</option>
option value="In Progress" class="form-control">In Progress</option>';
}
}
?>
</select>
<button name="save" id="save" class="form-control" style="width: 75px; float:right;margin-top: 6px">Save</button>
</form>
</td>
</tr>
<?php
endwhile;
endif;
endif;
?>
</table>
PHP - Bit that inserts into the DB
<?php
if(isset($_POST['save'])){
include '../Login-System/db.php';
$id = mysqli_real_escape_string($conn, $_POST['jobnumberid']);
$newtask = mysqli_real_escape_string($conn, $_POST['taskchanger']);
$sql = "UPDATE outstanding SET taskprogress = '$newtask' WHERE id = '$id'";
mysqli_query($conn, $sql);
header("Location: ../outstanding.php?updated");
exit();
} else {
header("Location: ../outstanding.php?whoops");
exit();
}
I have some code that at the moment, upon the page load up, doesn't display my table data, and when I type in a username into my text-box, it displays the data corresponding with the letters typed into the text-box to match the username characters.
I want it to automatically show my table data and make the username search optional, only display certain users when typed into the text-box.
My current code is below :
index.php
<form name="bulk_action_form" action="" method="POST"/>
<?php
if(isset($_POST['bulk_delete_submit'])) {
if(!empty($_POST['checked_id'])) {
$idArr = $_POST['checked_id'];
$username = $_SESSION['username'];
foreach($idArr as $id) {
mysqli_query($con, "DELETE FROM `users` WHERE `id` = '$id' AND `username` = '$username'");
echo "<p>".$id ."</p>";
}
$_SESSION['success_msg'] = 'Users have been deleted successfully.';
header("Location: admin_members.php");
} else {
echo '<div class="row" style="color: red; text-align: center; padding-bottom: 20px;"><i class="fa fa-spin fa-spinner"></i> You must select atleast one user to delete <i class="fa fa-spin fa-spinner"></i></div>';
}
}
?>
<div class="row">
<div class="card-box" style="border-radius: none; padding: 10px; border: 1px solid #E3E3E3; background: #EEEEEE;">
<button type="submit" class="btn btn-danger" name="bulk_delete_submit"><i class="fa fa-trash-o"></i></button>
</div>
</div>
<div id="result"></div>
</div>
</form>
(Ignore the , the result div is the main part, at listed for my JS code below).
JS in index.php
<script>
$(document).ready(function(){
$('#search_text').keyup(function(){
var txt = $(this).val();
if(txt != '') {
$.ajax({
url:"search.php",
method:"post",
data:{search:txt},
dataType:"text",
success:function(data)
{
$('#result').html(data);
}
});
} else {
$('#result').html('');
}
});
});
</script>
And then for my search.php
<?php
include_once('configuration/db.php');
?>
<div class="table-responsive">
<table class="table m-0">
<thead>
<tr class="gradeA">
<th><input type="checkbox" id="selectall"/></th>
<th style="text-align: center;">Username</th>
<th style="text-align: center;">Email</th>
<th style="text-align: center;">CPUKey</th>
<th style="text-align: center;">IP</th>
<th style="text-align: center;">Expirey</th>
<th style="text-align: center;">Enabled?</th>
<th style="text-align: center;">Profile Picture</th>
<th style="text-align: center;">User Level</th>
<th style="text-align: center;">Date/Time Registered</th>
<th style="text-align: center;">Account Credits</th>
<th style="text-align: center;">Free Gifted Credits</th>
</tr>
</thead>
<tbody>
<tr>
<?php
$username = $_SESSION['username'];
$clients_result = mysqli_query($con, "SELECT id, username, email, cpukey, ip, time, enabled, profile_picture, userLevel, register_time, account_credits, free_gifted_credits FROM users WHERE username LIKE '%".$_POST["search"]."%'");
if(mysqli_num_rows($clients_result) > 0) {
while($payment_row = mysqli_fetch_array($clients_result)) {
echo '
<tr style="text-align: center; font-size: 12px;">
<td>
<input type="checkbox" name="checked_id[]" class="checkbox" value='.($payment_row['id']).'>
</td>
<td>
'.($payment_row['username']).'
</td>
<td>
'.($payment_row['email']).'
</td>
<td>
'.$payment_row['cpukey'].'
</td>
<td>
'.($payment_row['ip']).'
</td>
<td>
<b>'.$payment_row['time'].'</b>
</td>
<td>
'.($payment_row['enabled'] == 1 ? '<span class="label label-success">Yes</span>' : '<span class="label label-danger">No</span>').'
</td>
<td>
'.("<img src=".$payment_row['profile_picture']." alt='user-img' class='img-circle user-img' style='height: 20px; width: 20px;'>").'
</td>
<td>
'.userLevelValidation().'
</td>
<td>
'.$payment_row['register_time'].'
</td>
<td>
'.number_format($payment_row['account_credits'], 2, '.', '').'
</td>
<td>
'.number_format($payment_row['free_gifted_credits'], 2, '.', '').'
</td>
';
;
} }else{ ?> <tr><td colspan="12" style="text-align: center; padding: 30px; letter-spacing: 2px; color: red;"><i class="fa fa-spin fa-spinner"></i> <strong>Oh snap!</strong> No Purchase records found. <i class="fa fa-spin fa-spinner"></i></td></tr> <?php } ?>
</tr>
</tbody>
</table>
</div>
<script type="text/javascript">
$('#selectall').click(function() {
$(this.form.elements).filter(':checkbox').prop('checked', this.checked);
});
</script>
Any help would be much appreciated.
I'm trying to delete the selected rows from the list I have in mysql so I won't have to delete the rows in my table one by one. When I press delete, my page refreshes without any php error but I don't get the result desired either. here is what I have:
<?php $product_set = find_all_products(); ?>
<body>
<form action="manage_products.php" method="delete">
<div class="page">
<article>
<div id="page">
<?php echo message(); ?>
<h2>Manage Products</h2>
<table>
<tr>
<th style="text-align: left; width: 125px;">Location</th>
<th style="text-align: left; width: 250px;">URL to the Product</th>
<th style="text-align: left; width: 100px;">First Name</th>
<th style="text-align: left; width: 100px;">Last Name</th>
<th style="text-align: left; width: 100px;">Size</th>
<th style="text-align: left; width: 100px;">Status</th>
<th style="text-align: left; width: 100px;">Checked</th>
<th colspan="2" style="text-align: left;">Actions</th>
</tr>
<?php while($product = mysqli_fetch_assoc($product_set)){ ?>
<tr>
<td><?php echo htmlentities($product["location"]);?></td>
<td><?php echo htmlentities($product["productURL"]); ?></td>
<td><?php echo htmlentities($product["fname"]); ?></td>
<td><?php echo htmlentities($product["lname"]); ?></td>
<td><?php echo htmlentities($product["size"]); ?></td>
<td><?php echo htmlentities($product["status"]); ?></td>
<td><input name="checkbox" type="checkbox" id="checkbox[]" value="<?php echo $product['id']; ?>"></td>
<td>Edit Order</td>
<td>Delete Order</td>
</tr>
<?php } ?>
</table>
<?php
// Check if delete button active, start this
if(isset($_GET['delete']))
{
$checkbox = $_GET['checkbox'];
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to delete_multiple.php
if($result){
$_SESSION["message"] = "Product deletion failed.";
redirect_to("created_products.php"); }
}
//mysqli_close($dbc);
?>
<br />
</div>
</div>
<br>
<input type="submit" name="submit" value="Delete" onclick="return val();"/>
</form>
<div class="clear-all"></div>
</article>
</div>
</body>
Also place all the code which is for deleting the rows in the starting of your file. Thank you #Traveller for this.
Instead of for loop, use WHERE IN
for($i=0;$i<count($checkbox);$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM product WHERE link_id='$del_id'";
$result = mysql_query($sql);
}
Replace that with
$ids = implode(",", $_POST['checkbox']);
$sql = "DELETE FROM product WHERE link_id in ($ids)";
DB MAP:
Carriers "table1": carriername, carrierid, ect... Post data
carrierinfo "table2": carriername, id, contact, ect... carrier list
I am using mysql_query from table2 for my carriername drop down. Using this I am able to post a carrier name to table1. I am trying to use the same drop down to post the related id from the selcected carriername. So in short I need to have one drop down that displays only the Carrier names but querys both carriername & id from table2. When the form is posted I need to post to the carriername & carrierid to table1. Below is the drop down I am using. Please let me know how I can connect the dots and add what is needed. If its possible.
<?php
if (isset($_POST["submit"]) && $_POST["submit"] == "Submit")
{
for ($count = 1; $count <= 9; $count++)
{
$fields[$count] = "";
if (isset($_POST["field" . $count . ""]))
{
$fields[$count] = trim($_POST["field" . $count . ""]);
//echo $fields[$count] . "<br />";
}
}
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$carrierid = mysql_real_escape_string($_POST['carrierid']);
$fromzip = mysql_real_escape_string($_POST['fromzip']);
$tozip = mysql_real_escape_string($_POST['tozip']);
$typeofequipment = mysql_real_escape_string($_POST['typeofequipment']);
$weight = mysql_real_escape_string($_POST['weight']);
$length = mysql_real_escape_string($_POST['length']);
$paymentamount = mysql_real_escape_string($_POST['paymentamount']);
$contactperson = mysql_real_escape_string($_POST['contactperson']);
$loadtype = mysql_real_escape_string($_POST['loadtype']);
$date = mysql_real_escape_string($_POST['date']);
$insert = "INSERT INTO Carriers (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW()) FROM carrierinfo WHERE id = '$carrierid'";
mysql_query($insert) or die(mysql_error());
$select = "SELECT `carriername` ,`fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` FROM `Carriers` ORDER BY `date` DESC;";
$result = mysql_query($select) or die(mysql_error());
}
?>
<style ="text-align: center; margin-left: auto; margin-right: auto;"></style>
</head>
<body>
<input type="button" onclick="window.location.href='search.php';" value="Search Board" /><div
style="border: 2px solid rgb(0, 0, 0); margin: 16px 20px 20px; width: 400px; background-color: rgb(236, 233, 216); text-align: center; float: left;">
<form action="" method="post";">
<div
style="margin: 8px auto auto; width: 300px; font-family: arial; text-align: left;"><br>
<table style="font-weight: normal; width: 100%; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<table
style="font-weight: normal; width: 100%; text-align: right; font-size: 12px;"
border="1" bordercolor="#929087" cellpadding="6" cellspacing="0">
<tbody>
<tr>
<td style="width: 10%;">Carrier:</td><td>
<?php
$con = mysql_connect("", "", "");
mysql_select_db("", $con);
$query=("SELECT * FROM carrierinfo");
$result=mysql_query($query) or die ("Unable to Make the Query:" . mysql_error() );
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
?>
</td>
</tr>
<tr>
<td style="width: 10%;">Load Type:</td><td>
<select name="loadtype">
<option></option>
<option value="TL">Truck Load</option>
<option value="Partial">Partial</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Pick Zip:</td><td> <input id="fromzip" name="fromzip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Drop Zip:</td><td> <input id="tozip" name="tozip" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Weight:</td><td> <input id="weight" name="weight" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Length:</td><td> <input id="length" name="length" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 10%;">Equip:</td><td>
<select name="typeofequipment">
<option></option>
<option value="AUTO">Auto Carrier</option>
<option value="DD">Double Drop</option>
<option value="F">Flatbed</option>
<option value="LB">Lowboy</option>
<option value="Rail">Rail</option>
<option value="Ref">Reefer</option>
<option value="RGN">Removable Goose Neck</option>
<option value="SD">Step Deck</option>
<option value="TANK">Tanker (Food, liquid, etc.)</option>
<option value="V">Van</option>
</select>
</td>
</tr>
<tr>
<td style="width: 35%;">Contact:</td><td> <input id="contactperson" name="contactperson" maxlength="50"
style="width: 100%;" type="text">
</tr>
<tr>
<td style="width: 35%;">Rate:</td><td> <input id="paymentamount" name="paymentamount" maxlength="50"
style="width: 100%;" type="text">
</tr>
</tbody>
</table>
<p style="text-align: center;"><input name="submit" value="Submit"
class="submit" type="submit"><input type="button" onclick="window.location.href='newcarrier.php';" value="Add Carrier" /></p>
</div>
</form>
</div>
<p style="margin-bottom: -20px;"> </p>
</body>
Use a join:
SELECT t1.carrierid, t2.carriername, t2.id
FROM table1 t1 JOIN table2 t2 USING (carriername)
Joining tables should be one of the first things you learn when studying SQL.
UPDATE:
Never mind the above, your original query to populate the dropdown was correct. When you populate the select, you should do:
echo "<select name='carrierid'>";
while($row=mysql_fetch_array($result)){
echo "<OPTION VALUE='".$row['id']."'>".$row['carriername']."</OPTION>";
}
echo "</select>";
When posting the data, get rid of this line:
$carriername = mysql_real_escape_string($_POST['carriername']);
and change the insert query to:
$insert = "INSERT INTO Loads (`carriername` ,`carrierid`, `fromzip` ,`tozip` ,`typeofequipment` ,`weight` ,`length` ,`paymentamount` ,`contactperson` ,`loadtype` ,`date`)
SELECT carriername ,'$carrierid' ,'$fromzip' ,'$tozip' ,'$typeofequipment' ,'$weight' ,'$length' ,'$paymentamount' ,'$contactperson' ,'$loadtype', NOW())
FROM Carriers
WHERE id = '$carrierid'";
The change to the form makes it display the carrier name, but return the ID in the post data. Then the new INSERT query uses that ID to get the carrier name from table 2 and combine that with all the other post data when inserting into table 1.
I have a very simple IF statement that worked for me a week ago, but mysteriously doesn't work for me now. I have a field when selected, creates an extra query.
The problem is, the doc is completely skipping over my if statement like it doesn't even exist
Here's the WHOLE CODE
<body id="bdy" onload="javascript:fg_hideform('fg_formContainer','fg_backgroundpopup');">
<div class="container_22" id="container">
<div id="rootDiv">
<div style="background-color: rgb(255, 255, 255);"
id="wrapper">
<div class="main">
<div id="mainMiddle" class="main-middle">
<div id="content" class="wide-content"
style="position: relative; width: 990px; background-color: rgb(255, 255, 255);
display: inline; margin-left:
15px;">
<span id="cntntMiddle_bannerTop"></span><!-- =search-bar | start -->
<div id="cntntMiddle_SearchBoxContainer"
style="margin-top: 20px; padding-left: 20px;">
<form action="search.php" class="search-bar" method="GET">
<h3>Search</h3>
<fieldset>
<div class="ctrlHolder inline">
<input type="checkbox" name="r" id="r" value="y">
Return Flight?
</div>
<div class="ctrlHolder
inline">
<input type="hidden" class="fnc-direction" id="curusd" name="Currency" value="USD" /> </div> <div id="trip-1" class="fnc-trip first"> <h6 ><span id="flight1">Departing Flight</span> </h6> <div
class="ctrlHolder"> <label for="from-1"> <span class="left">From</span> <span class="right">(City or Airport)</span> </label> <?php
$autocomplete1 = array();
mysql_connect('localhost', '', '');
mysql_select_db('');
$sql = "SELECT distinct rout_from FROM search_v ORDER BY rout_from ASC";
$r = mysql_query($sql);
while ($row = mysql_fetch_array($r))
{
$autocomplete1[] = $row['rout_from'];
}
?><input id="newsearch1" name="departure_label">
</div> <div class="ctrlHolder"><label for="from-1"> <span class="left">To</span> <span class="right">(City or Airport)</span> </label> <?php
$autocomplete = array();
mysql_connect('localhost', '', '');
mysql_select_db('');
$sql = "SELECT distinct rout_to FROM search_v ORDER BY rout_to ASC";
$r = mysql_query($sql);
while ($row = mysql_fetch_array($r))
{
$autocomplete[] = $row['rout_to'];
}
?><input id="newsearch" name="arrival_label"> </div> <div class="ctrlHolder"> <label for="leave-1">Depart</label>
<input type="text" id="f" name="txtDate1"/> </div> <div class="ctrlHolder"> <label for="leave-2">Arrive</label>
<input type="text" id="t" name="txtDate2"/></div> </div> </fieldset> <fieldset class="travelers">
<legend>Travelers
</legend>
<div class="ctrlHolder inline-select clearfix">
<div class="field">
<label for="adults">
<br />
Passengers</label>
<select
name="ddlPAxADT" id="ddlPaxADT">
<option selected="selected"
value="1">1</option><option value="2">2</option><option
value="3">3</option><option value="4">4</option><option value="5">5</option>
</select>
</div>
<br>
</div>
</fieldset>
<div class="submit-wrap
clearfix">
<button class="btn-reset" type="reset">
Reset
</button>
<input
name="submit" class="btn-search" type="submit" />
</div>
</form>
</div>
<div id="cntntMiddle_search-results" class="search-results">
<span id="cntntMiddle_lblResults"> <h2>Search Results</h2> <h3>Showing <span id="cntntMiddle_ctl01_lblFlightFilter">all
results</span></h3>
<?php
mysql_connect('localhost', '', '');
mysql_select_db('');
$search = $_GET['search'];
$sfrom = $_GET['departure_label'];
$sto = $_GET['arrival_label'];
$sfromda = $_GET['txtDate1'];
$stoda = $_GET['txtDate2'];
$padt = $_GET['ddlPaxADT'];
$currency = $_GET['Currency'];
$ret = $_GET['r'];
if ($ret!='y') {
$sql1 = mysql_query("SELECT * FROM search_v WHERE rout_to='$sfrom' AND rout_from='$sto' AND date_avialable='$stoda'") or die(mysql_error());
$runrows1 = mysql_fetch_array($sql1);
$flightid1 = $runrows1['flight_id'];
$aseats1 = $runrows1['seats_avialable'];
$todate1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['to_date']));
$date1 = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows1['date_avialable']));
$from1 = $runrows1['rout_from'];
$to1 = $runrows1['rout_to'];
$acost1 = $runrows1['adult_cost'];
$ccost1 = $runrows1['child_cost'];
$cur1 = $runrows1['currency'];
$oth1 = $runrows1['other_cost'];
$totalcost1= $acost1+$oth1;
$pr1 = $flightid1+5;
}
//echo outconstruct
$sql = mysql_query("SELECT * FROM search_v WHERE currency='$currency' AND
rout_to='$sto' AND rout_from='$sfrom' AND DATE_FORMAT(date_avialable,'%Y-%m-%d')
between'".$sfromda."' and '".$stoda."' LIMIT 10") or die(mysql_error()) ;
while ( $runrows = mysql_fetch_array($sql))
{
//get data
$flightid = $runrows['flight_id'];
$aseats = $runrows['seats_avialable'];
$todate = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['to_date']));
$date = strftime("%b %d, %Y %l:%M %p" ,strtotime($runrows['date_avialable']));
$from = $runrows['rout_from'];
$to = $runrows['rout_to'];
$acost = $runrows['adult_cost'];
$ccost = $runrows['child_cost'];
$cur = $runrows['currency'];
$oth = $runrows['other_cost'];
$totalcost= $acost+$oth;
$pr = $flightid+5;
echo "";
?>
<?PHP
include('popup/contactform-code.php');
?>
<ul class="result-list clearfix">
<li class="item clearfix">
<span
id="cntntMiddle_ctl01_rptmain_lblFromt_0">
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="price">Price<?php echo $ret; ?></th>
<th>From</th>
<th>To</th>
<th>Depart</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="6">
<div class="select-wrap">
<p class="seats">
<strong><?php echo $aseats; ?></strong><span>seats
left</span><em>at this price</em>
</p> <a href='javascript:fg_popup_form("fg_formContainer","fg_form_InnerContainer","fg_backgroundpopup");'
><img border='0' src='images/select_flight.png' width='121' height='34' /></a>
</div></td>
</tr>
</tfoot>
<tbody>
<tr>
<td class="price" rowspan="2"><a
style="font-weight: bold; cursor: pointer; text-decoration: none;"
herf="#" onclick='return ray.ajax("#");'><span
style="font-size: 24px; font-weight: bold;"><?php echo $totalcost; ?></span><span
style="font-size: 11px; margin-top: 2px; display: block; color: rgb(255, 255,
255); text-align: center; font-
weight: normal;">per
person</span><span
style="font-size: 12px; margin-top: 2px; display: block; color: rgb(255, 255,
255); text-align: center; font-
weight: normal;">(with fees)</span></a></td>
<td><?php echo $from; ?></td>
<td><?php echo $to ?></td>
<td style="padding-right: 2px;"><?php echo $date; ?></td>
</tr>
<tr>
<td><?php echo $to1; ?></td>
<td><?php echo $from1 ?></td>
<td style="padding-right: 2px;"><?php echo $date1; ?></td>
</tr>
</tbody>
</table> </span><a
id="cntntMiddle_ctl01_rptmain_lblResultDetails1_0" title="1"
href="javascript:__doPostBack('ctl00$cntntMiddle$ctl01$rptmain
$ctl00$lblResultDetails1','')"
style="color: Black;"></a><a class="close"
href="#">Close</a>
<div class="info clearfix">
<div class="info clearfix">
<h4>Departing Flight</h4>
<ul class="clearfix">
<li>
<h5><?php echo $from; ?> to <?php echo $to; ?> <?php echo $date; ?></h5>
<ul>
<li>
</li>
<li>
<strong>Flight #</strong> - <?php echo $flightid; ?>
</li>
<li>
<strong>Departure Time – </strong>
<?php echo $date; ?>
</li>
</ul>
</li>
</ul>
<ul>
<li style="padding-top: 5px;">
<span
style="color: rgb(212, 22, 13); font-weight: bold; font-size: 11px; text-
decoration: none;"> Fare Breakdown</span>
</li>
</ul>
<table class="more">
<tbody>
<tr>
<th>Passenger</th>
<th>Fare</th>
<th> Taxes and Fees</th>
<th>Qty</th>
<th>Total Cost</th>
</tr>
</tbody>
<tbody>
<tr>
<td>Adult</td>
<td
style="color: rgb(100, 100, 100); font-size: 11px; font-weight: bold;"><?php
echo $acost; ?></td>
<td><?php echo $oth; ?></td>
<td id="paxAdtTd">1</td>
<td><?php echo $acost; ?></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td>Cost of Sale(<?php echo $cur; ?>)</td>
<td> </td>
<td
style="color: rgb(100, 100, 100); font-size: 14px; font-weight: bold;"><?php
echo $totalcost; ?></td>
</tr>
</tbody>
</table>
<br />
<span style="font-weight: bold; padding-top: 10px;"> *Additional airline fees for baggage may apply</span>
<div class="select-wrap">
<p class="seats">
<strong><?php echo $aseats; ?></strong><span>seats
left</span><em>at this price</em>
</p>
<button class="btn-select" type="button" id="start">
Select
Flight
</button>
</div>
</li>
</ul> </ul>
</ul>
<?php ;}?>
</div>
</div>
I think it's because of trailing newline character. So, before you actually do if($ret != 'y') just trim it $ret = trim($ret). give it a try.
$ret = $_GET['r'];
$ret = trim($ret);
if ($ret!='y')
{
// rest of your code
}
Try something like:
<?php
$ret = $_GET['r'];
if($ret != "y") {
echo "Yay!";
} else {
echo ":(";
}
?>
<html>
<head>
</head>
<body>
<form method="get" action="search.php">
<input type="checkbox" value="y" name="r" />Submit Query<br />
<input type="submit" value="Submit" name="submit" />
</form>
</body>
</html>