I’m pretty new to PHP, at least, as an overall thing. I know it well enough to easily work in Wordpress and create custom templates and the like.
But now I’m stuck working on a PhpMyDirectory site and its just set up very differently so I’m running up against my lack of comprehensive knowledge.
All I need to do is query the DB to join to tables to output a list of city names.
But when I get to the front end, all I get is either “Array” or only the first city (I tried two different solutions).
Could someone please point me in the right direction, I’ve spent way too long on something that shouldn’t be this difficult. The way PHPmyDirectory is set up, there’s a php code page, and then a .tpl template page for output.
This code got me the “array” output on the frontend:
PHP page:
[php] $city_titles = $db->GetAll(“SELECT SQL_CALC_FOUND_ROWS r.*, r.city_id AS city_id, locations.title AS location_title FROM “.T_LISTINGS_CITIES.” r LEFT JOIN “.T_LOCATIONS.” locations ON locations.id=city_id WHERE listing_id=”.$listing[‘id’]." ");
$city_serve=mysqli_query($city_titles);
while($cities=mysqli_fetch_assoc($city_serve)):
$city_title = $city_serve[‘location_title’];
$output .= '<li>' . $city_title . '</li>';
endwhile;
$template_content->set('city_listings', $city_titles);[/php]
This code got me the one city result combined with a while loop on the frontend template:
[php]$cities_records = $db->getall(“SELECT city_id FROM “.T_LISTINGS_CITIES.” WHERE listing_id=”.$listing[‘id’]." ");
// die(print_r($listing_records));
if(count($cities_records) >= 1) {
$new_counter = 0;
foreach($cities_records as $city_served) {
$new_counter ++;
$city_title = $db->getrow("SELECT title FROM ".T_LOCATIONS." WHERE id=".$city_served['city_id']." ");
}
$city_text = $city_title['title'];
$template_content->set('city_listings', $city_text);
}
[/php]
frontend code:
[php]<?php if($city_listings) {
while ($city = $city_listings) { ?>
<li><?php echo $city; ?></li>
<?php } ?>
<?php } ?>[/php]
It appears I’m not getting my loop to loop but I don’t see what I’m missing. I’d really appreciate some help, as I’m getting very frustrated. Thank you very much.