requesting listings with certain ID's
8 posts by 3 authors in: Forums > CMS Builder
Last Post: March 17, 2012 (RSS)
By loccom - March 9, 2012
I am trying to import a load of data into CMSB
However, its split in to 3 tables
1. hotel Information
2. Hotel Facilities
3. Hotel Image source links
I know how to call data in to my template from 3 different tables but not how to call everything with a certain ID
In the detailed listing of the hotel info I want to pull in all images related to this hotel. The image Database fields are
image_id
title
url
hotel_id
service_id
I wish to call everything from the Image table with the same "hotel_id" so from the template I am calling the table called Images and everything with the hotel_id and then displaying the image url's in one list in the template.
hope this makes sense?
thanks
Re: [loccom] requesting listings with certain ID's
By Jason - March 9, 2012
So if I understand correctly, on your page you have a hotel record which has a hotel id. You then want to get all of the records from the hotel image source links section that has the same hotel_id as your current record. Is that right?
If so, here is an example of how you can do that. Here I've assumed that you have a variable called $hotel which is your current hotel record and I've had to guess at the exact name of your section.
EXAMPLE:
list($hotelImageRecords, $hotelImageMetaData) = getRecords(array(
'tableName' => 'hotel_image_source_links',
'allowSearch' => false,
'where' => "hotel_id = '".mysql_escape($hotel['hotel_id'])."'",
));
Hope this helps
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Re: [Jason] requesting listings with certain ID's
By loccom - March 9, 2012
I will give that a try.
thanks!
Re: [loccom] requesting listings with certain ID's
By loccom - March 16, 2012
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/newsdesk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// load records
list($lateroom_imagesRecords, $lateroom_imagesMetaData) = getRecords(array(
'tableName' => 'lateroom_images',
'where' => false,
'where' => "hotel_id = '".mysql_escape($url['199269'])."'",
));
$lateroom_imagesRecord = @$lateroom_imagesRecords[0]; // get first record
// show error message if no matching record is found
if (!$lateroom_imagesRecord) { dieWith404("Record not found!"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>
<?php echo $lateroom_imagesRecord['url'] ?>
</body>
</html>
Here are the fields in the db
image_id (unique id of image)
title (hotel name)
url (url to hotel image)
hotel_id (the hotels id)
Imagine the hotel i need is ID number 999, I am trying to call all the image url's with the same "hotel_id" of 999 and then display them in a list.
Where am i going wrong?
Re: [loccom] requesting listings with certain ID's
By (Deleted User) - March 16, 2012
I think what you want to do is this:
// get all the images where the hotel_id is '999'
list($lateroom_imagesRecords, $lateroom_imagesMetaData) = getRecords(array(
'tableName' => 'lateroom_images',
'where' => "hotel_id = '999'",
));
// get the first record
$lateroom_imagesRecord = @$lateroom_imagesRecords[0];
If the hotel_id is being passed in the URL and is the last number in the url, you could use:
// get all the images where the hotel_id is that found in the url
$where = "hotel_id = '".getLastNumberInUrl()."'";
list($lateroom_imagesRecords, $lateroom_imagesMetaData) = getRecords(array(
'tableName' => 'lateroom_images',
'where' => $where,
));
Let me know if that helps,
Tom
Re: [Tom P] requesting listings with certain ID's
By loccom - March 16, 2012
Its almost there ;)
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/newsdesk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }
// get all the images where the hotel_id is '999'
list($lateroom_imagesRecords, $lateroom_imagesMetaData) = getRecords(array(
'tableName' => 'lateroom_images',
'where' => "hotel_id = '999'",
));
// get the first record
$lateroom_imagesRecord = @$lateroom_imagesRecords[0];
// show error message if no matching record is found
if (!$lateroom_imagesRecord) { dieWith404("Record not found!"); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<style type="text/css">
body { font-family: arial; }
.instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
</style>
</head>
<body>
<?php echo $lateroom_imagesRecord['url'] ?>
</body>
</html>
Re: [loccom] requesting listings with certain ID's
By (Deleted User) - March 16, 2012
It's only showing one result because of the line:
$lateroom_imagesRecord = @$lateroom_imagesRecords[0];
If you want to show all the images, remove that line and then add the following in place of "<?php echo $lateroom_imagesRecord['url'] ?>":
<?php
if ( @$lateroom_imagesRecords ) {
foreach ($lateroom_imagesRecords as $record ) {
echo $record['url']."<br>";
}
}
?>
This loops over all the returned records and outputs each url (each on on a new line).
Hope this helps,
Tom
Re: [Tom P] requesting listings with certain ID's
By loccom - March 17, 2012