Field from url

7 posts by 3 authors in: Forums > CMS Builder
Last Post: June 26   (RSS)

By mbareara - June 25

Hi and thank you in advance for your help

I have a url like this http://www.blabla/list.php?city=taormina 

I would have something like "There are 13 results in TAORMINA" recalling the field city (Taormina in this case) from url. Is it possible?

Orazio

By gkornbluth - June 25

Hi Orazio,

How are you generating the URL with the city name?

Thanks,

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By mbareara - June 25

i'm generating it with this code <a href="https://www.****.com/locali/list.php?city=<?php echo htmlencode($record['city']) ?>">

By gkornbluth - June 25

If all you want is a list of the cities and how many there are in each city, then you should be able to use the groupBy function as in the example below, and modify the code to suit your needs.

You can see the result of this at https://dbtproviders.com/maplist.php

<?php list($accountsRecords, $accountsMetaData) = getRecords(array(
'tableName' => 'accounts',
'orderBy' => 'practice_country ASC, practice_state ASC',
'groupBy' => 'practice_country, practice_state',
)); ?>

<!-- Insert Active Code Here -->

<div align="center" style="width:80%; text-align:left"><span class="heading_font"><b>PROVIDER MAPS</b><br />
<br />
</span> <span class="text_font">We have provider listings in the following Countries/States/Provinces<br />
Choose the one that's right for you</span><br />
<br />
<div class="rTable">
<div class="rTableBody">
<?php $old_group = ''; // init blank var.

foreach ($accountsRecords as $record): ?>
<?php if (!$record['practice_country:label'] == '' ):?>
<?php $group = $record['practice_country:label']; // load sub-group value from record. ?>
<?php else : ?>
<?php $group = $record['other_practice_country']; ?>
<?php endif ?>
<?php $stateCount = mysql_count('accounts', mysql_escapef("`practice_state` = ? AND `hidden` = '0' ",$record['practice_state'])); ?>
<?php $countryCount = mysql_count('accounts', mysql_escapef("`practice_country` = ? AND `hidden` = '0' ",$record['practice_country'])); ?>
<div class="rTableRow">
<div class="rTableCell text_font">
<?PHP
if ($group !== $old_group) {echo "<h3>$group ($countryCount Listings)</h3>";} ?>
<?php $state = ($record['practice_state']); ?>
<?php $country = ($record['practice_country:label']); ?>
<?php $recnum = ($record['num']); ?>
<a href="maps.php?state=<?php echo $state ?>&country=<?php echo $country ?>"><?php echo ucwords($state); ?> (<?php echo $stateCount ?>) </a></div>
</div>
<?PHP $old_group = $group; // retain sub-group name before moving to new record. ?>
<?php endforeach; ?>
</div>
</div>
</div>

If you're looking for the visitor to do a search to determine the city in question, you can take a look at some of the recipes, like http://www.thecmsbcookbook.com/recipedetail.php?Allowing-Visitor-To-Set-Where-values-444 or the "Search" recipes in my CMSB Cookbook (free trial link below) to search for a city by name and then use the resulting records to give a record count:

<?php $count = "" // reset Counter ?>
<?php foreach ($your_sectionRecords as $record): ?>
<?php $count++ // increment the counter by +1 ?>
<?php endforeach?>

And then echo that count along with the city name searched for

Hope that helps

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By Damon - June 25

HI Orazio,

To get this result:

"There are 13 results in TAORMINA

Try using this code:

<?php if (@$_REQUEST['city']) : ?>
There are <?php echo $newsMetaData['totalRecords']; ?> results in <?php echo $_REQUEST['city']; ?><br />
<?php endif; ?>

Replace $newsMetaData with the name of your section editor (table).

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By mbareara - June 26

Thanks Damon and Jerry!