Jump to:

22999 Posts in 11854 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » database row count

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 940 Views
  • ryeze
    Avatar
    Community Member
    6 Posts

    database row count Link to this post

    hi. I have a database table like that in the attached file. I want count number of database rows. if in sql may look something like this, SELECT count (KotaPenerima) FROM `student` WHERE KotaPenerima = 'Jawa Barat'. How do I put this function, and if I want to display query results on the front page.

    thanks.

    Attached Files
  • Devlin
    Avatar
    Community Member
    186 Posts

    Re: database row count Link to this post

    Page.php

    function Students() {
    $students = DataObject::get('Student', "KotaPenerima = 'Jawa Barat'");
    return !empty($students) ? $students : false;
    }

    Page.ss

    <% if Students %>
    student count: $Students.Count
    <% control Students %>
    student lastname: $Lastname
    <% end_control %>
    <% end_if %>

    http://doc.silverstripe.org/sapphire/en/topics/datamodel
    http://doc.silverstripe.org/sapphire/en/reference/advanced-templates

  • ryeze
    Avatar
    Community Member
    6 Posts

    Re: database row count Link to this post

    Hi devlin .. thanks for your quick response.
    Wow ..
    it's work, Thank you very much.

    I'm still a newbie in using SilverStripe.
    but I found another problem, I would like the 'KotaPenerima' a variable that contains all of the 'KotaPenerima, not just 'JawaBarat'. may be an array, I do not know what to put where the array functions?

    so that I can display the count of each 'KotaPenerima'.

    940 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.