SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Adding plural s when fetching data from db (was:Ssssssssssssssssssssss)

    In the script below, 'Name' summons the name of a state, while 'DesigGeneral' summons the name of a state symbol. Thus, it might display "Arizona's State Mammal."

    PHP Code:
    <?php
    if($r['Symbol'] !=''):
    $ChildName $r['Name'] . "’s State " strtotitle($r['DesigGeneral']);
    endif; 
    ?>
    But some states have several official mammals, each represented by a unique row in my database table that looks something like this:

    DesigGeneral | Symbol
    Mammal | white-tailed deer
    Mammal | raccoon
    Mammal | Morgan horse

    How can I modify my script so that it adds an S if there are more than one entries for 'DesigGeneral'? In other words, I'd like it to display...

    Arizona's State Mammal
    Texas' State Mammals

    Thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    40
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    try something like that.

    if (mysql_num_rows($whatever) > 1) $ChildName .= 's';

  3. #3
    Non-Member
    Join Date
    Jan 2004
    Location
    Seattle
    Posts
    4,328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GStyle
    Hi there,

    try something like that.

    if (mysql_num_rows($whatever) > 1) $ChildName .= 's';
    Can you see what I'm doing wrong? Below is my script, followed by the error message I got. Thanks.

    PHP Code:
    <?php
    // TITLE & NAVHERE
    if($r['Symbol'] !=''):
    $ChildName $r['Name'] . "’s State " strtotitle($r['DesigGeneral']);
    else:
    $ChildName $data_details['Name'] . "’s State " $mytopic ", etc.";
    endif;

    if (
    mysql_num_rows($r['DesigGeneral']) > 1$ChildName .= 's';
    ?>
    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in [URL] on line 314

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    73
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mysql_num_rows wants a as parameter the result of a mysql_query.
    You are giving him just an array...
    There is no signature...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •