Hi,
First time poster -but this site has helped me out tremendously so far - so fingers crossed with this…
It may seem too simple but I have been struggling with this all day.
i am following the php/mysql book - the jokes database etc -but have hit a wall.
In my search form I have:
<div>
<label for="location">By location:</label>
<select name="location" id="location">
<option value="">Any location</option>
<?php foreach ($locations as $location): ?>
<option value="<?php htmlout($location['locationid']); ?>"><?php
htmlout($location['location']); ?></option>
<?php endforeach; ?>
</select>
</div>
That’s grand - I can select my locations no problem - all set up fine in my controller index.php (this is one out of 3 drop down boxes to search with)
Now when i want to return the results I cannot get the location, just locationid
index.php
if (isset($_GET['action']) and $_GET['action'] == 'search')
{
include $_SERVER['DOCUMENT_ROOT'] . '/includes/db.inc.php';
// The basic SELECT statement - to do nothing - will have no effect on results unless added to
$select = 'SELECT *';
$from = ' FROM tbljob';
$where = ' WHERE TRUE';
$companyid = mysqli_real_escape_string($link, $_GET['company']);
if ($companyid != '') // A company is selected
{
$where .= " AND companyid='$companyid'";
}
$locationid = mysqli_real_escape_string($link, $_GET['location']);
if ($locationid != '') // A location is selected
{
$where .= " AND locationid='$locationid'";
}
$categoryid = mysqli_real_escape_string($link, $_GET['category']);
if ($categoryid != '') // A category is selected
{
$where .= " AND categoryid='$categoryid'";
}
//matches categoryid in table with the categoryid in form
$jobdesc = mysqli_real_escape_string($link, $_GET['jobdesc']);
if ($jobdesc != '') // Some search text was specified
{
$where .= " AND jobdesc LIKE '%$jobdesc%'";
}
$result = mysqli_query($link, $select . $from . $where);
if (!$result)
{
$error = 'Error fetching jobs line109.';
include 'error.html.php';
exit();
}
while ($row = mysqli_fetch_array($result))
{
$jobs[] = array( 'jobtitle' => $row['jobtitle'], 'jobref' => $row['jobref'], 'jobsalshow' => $row['jobsalshow'], 'locationid' => $row['locationid'], 'location' => $row['location']);
}
include 'jobs.html.php';
exit();
}
I have a problem when displaying the results. i can’t figure out how to link my locationid (tbljobs.locationid) to location (tblLocation.location).
How do I put ‘location’ => $row[‘location’] into the jobs array? I can’t figuere out how i can change the $result variable output or if that’s even what i do…
Any tips at all would be be brill - thanks a mill, Lynn