SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Australia
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Quick Way please

    Is there any quicker way to do the following:

    PHP Code:
    $sql "select * from main where Category='Immigration' AND State='WA'"
    $rows mysql_query($sql); 
    $numrows mysql_num_rows($rows); 
    echo 
    "$numrows"
    Thanks,
    Ajay

  2. #2
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yup
    PHP Code:
    $sql "select COUNT(*) AS numrows from main where Category='Immigration' AND State='WA'";
    $rows mysql_query($sql);
    $numrows mysql_result($rows0);
    echo 
    $numrows
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  3. #3
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How about this:

    PHP Code:
    $numrows = @mysql_result(@mysql_query("select COUNT(*) from main where Category='Immigration' AND State='WA'"), 0); 
    Last edited by platinum; Apr 22, 2003 at 05:10.

  4. #4
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by platinum
    PHP Code:
    $numrows = @mysql_result(@mysql_query("select * from main where Category='Immigration' AND State='WA'"), 0); 
    Wouldn't that just return the first field of the first column?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  5. #5
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work exactly the same as yours (I was too slow in hitting the submit button ) - but it's mushed into one line, I use that (or a similar) query to count the number of posts on articles and it seems to work okay

  6. #6
    Sidewalking anode's Avatar
    Join Date
    Mar 2001
    Location
    Philadelphia, US
    Posts
    2,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Weird...you're sure you don't have a COUNT() in that query and just forgot it for this?
    TuitionFree a free library for the self-taught
    Anode Says... Blogging For Your Pleasure

  7. #7
    + platinum's Avatar
    Join Date
    Jun 2001
    Location
    Adelaide, Australia
    Posts
    6,441
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    whoops

    Thanks for picking that up
    I had just copied his query into my existing one which - forgot to change the count...

  8. #8
    Non-Member
    Join Date
    Jan 2003
    Posts
    5,748
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    LoL
    LoL
    LoL... etc etc

  9. #9
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Location
    Australia
    Posts
    89
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi

    The reason I wanted to this was that I've made a business directory script and I want to display the number of listings for each category.

    I've got about 30 categories and I don't think it would be logical to copy that code 30 times on the same page.

    Is there any way to do that.

    If it helps here is the url of a page http://www.indiaoz.com.au/business_directory/wa.php I want the number of listings in each category to display next to the category name.

    Thanks,
    Ajay


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
  •