Displaying records

15 posts by 2 authors in: Forums > CMS Builder
Last Post: April 20, 2011   (RSS)

Hello,
Is there a post or an easy way to list how many records are returned after a search? For example, the user does a search and it returns 25 results but there are 100 listings in the database total...I would like it to be something like: Showing 1 - 25 Of 100 to let the user know how many results were returned.

Thanks!
April

Re: [apdance9] Displaying records

By Jason - December 13, 2010

Hi April,

You can do this using the meta data that we return using get Records.

For example:
list($articleRecords,$articleMetaData)=getRecords(array(
'tableName' => 'articles',
'perPage' => 10,
));


We can output your information like this:

Showing <?php echo $articleMetaData['pageResultsStart'];?> - <?php echo $articleMetaData['pageResultsEnd'];?> of <?php echo $articleMetaData['totalRecords'];?>

The first two values will change depending on what page you're on. $articleMetaData['totalRecords'] will display the total records returned by the query, not necessarily all the records in the database. If you want to show the number of records in a particular table, you can try this:

<? echo mysql_select_count_from('articles','');?>

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: [apdance9] Displaying records

By Jason - December 13, 2010

Hi April,

What happened is you used $$ when outputting your totalRecords.

Try this:
<?php echo $mag_locaterMetaData['totalRecords'];?>

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] Displaying records

By design9 - April 18, 2011

I am using the following on my page (Showing <?php echo $articleMetaData['pageResultsStart'];?> - <?php echo $articleMetaData['pageResultsEnd'];?> of <?php echo $articleMetaData['totalRecords'];?>) to display number of records found. I now have two sections set-up now where one area is premium listings that I am displaying by an php if statement I wrote based on a checkbox in the backend( if checked it displays as a premium listing). Then I have my regular listings which shows all listings. My question is there a way to show how many records are returned in both sections? I want the premium area to show how many records are returned as well as the regular listings which shows 53 listings. I didn't know how to seperate these out.

Here is the page I am talking about: http://www.charlotteparent.com/directories/urgentcare/test.php

Thanks,

April

Re: [design9] Displaying records

By Jason - April 18, 2011

Hi April,

Are you combining results from more than one query, or does only one query get displayed at any given time?

If you could attach test.php to this thread, I can take a closer look and give you some suggestions.

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] Displaying records

By design9 - April 18, 2011

Both sections are pulling the same data from the table called "urgentcare_list" (multi-viewer). The premium are ones where the user is paying a fee to have those listed as premium and those are indicated with a checkbox in backend where I have written a simple if statement to display those.



File is attached.

thank you,

~A
Attachments:

test_015.php 51K

Re: [design9] Displaying records

By Jason - April 19, 2011

Hi,

Probably the best way to do it would be to do 2 separate queries using the WHERE clause. That way you wouldn't have to worry about your if statement.

For example:

$addressRecords = array();
if ($myLat && $myLng) {
$maxDist = floatval(@$_REQUEST['maxDistance']);
list($premium_listRecords, $premium_listMetaData) = getRecords(array(
'tableName' => 'urgentcare_list',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles). " AND pre_listing = '1'", // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
));


list($urgentcare_listRecords, $urgentcare_listMetaData) = getRecords(array(
'tableName' => 'urgentcare_list',
'addSelectExpr' => geocoder_getSelectExprForDistance($myLat, $myLng, '_distance', $kmOrMiles), // adds '_distance' field to output records
'where' => geocoder_getWhereForDistanceWithin($myLat, $myLng, $maxDist, $kmOrMiles). "AND pre_listing = '0'", // optimization: remove results outside of minimum bounding rectangle
'having' => "_distance <= " . $maxDist, // only show results within max distance
'orderBy' => 'ISNULL(_distance), _distance', // sort nearest records first -and- unknown or undefined distances last
));
}


So $premium_listRecords only has your premium records and $urgentcare_listRecords has all your non premium records.

Would this work for you?

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] Displaying records

By design9 - April 19, 2011

Thank you Jason!

That will probably not work because all the data is the same and with having two queries, we would have to input the same data in twice. They only want to input the data in one editor/section. Is there any other way to display how many records are displaying?

Thanks!

Re: [design9] Displaying records

By Jason - April 19, 2011

Hi April,

In the example I posted, all of the information is being pulled from the same section, so it wouldn't need to be inputted twice. We're just using 1 query to get the records where premium was checked, and 1 query to get the records where it was not checked.

Does that help?
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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