Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9082383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:32:46+00:00 2026-06-16T20:32:46+00:00

I’m trying to modify a voting script(Thumbsup) I need this query to only return

  • 0

I’m trying to modify a voting script(Thumbsup) I need this query to only return only array items that have their ‘cat’ => ‘1’ in the subarray (proper term?)

<?php $items = ThumbsUp::items()->get() ?>

Here’s an example of the live generated array from my database

array (
  0 => 
  array (
    'id' => 1,
    'name' => 'a',
    'cat' => '1',
  ),
  1 => 
  array (
    'id' => 2,
    'name' => 'b',
    'cat' => '2',
  ),
  2 => 
  array (
    'id' => 3,
    'name' => 'c',
    'cat' => '2',
  ),


)

Is this possible by just modifying the query?

edit: heres function get()

public function get()
{
    // Start building the query
    $sql  = 'SELECT id, name, url, cat, closed, date, votes_up, votes_down, ';
    $sql .= 'votes_up - votes_down AS votes_balance, ';
    $sql .= 'votes_up + votes_down AS votes_total, ';
    $sql .= 'votes_up / (votes_up + votes_down) * 100 AS votes_pct_up, ';
    $sql .= 'votes_down / (votes_up + votes_down) * 100 AS votes_pct_down ';
    $sql .= 'FROM '.ThumbsUp::config('database_table_prefix').'items ';

    // Select only either open or closed items
    if ($this->closed !== NULL)
    {
        $where[] = 'closed = '.(int) $this->closed;
    }

    // Select only either open or closed items
    if ($this->name !== NULL)
    {
        // Note: substr() is used to chop off the wrapping quotes
        $where[] = 'name LIKE "%'.substr(ThumbsUp::db()->quote($this->name), 1, -1).'%"';
    }

    // Append all query conditions if any
    if ( ! empty($where))
    {
        $sql .= ' WHERE '.implode(' AND ', $where);
    }

    // We need to order the results
    if ($this->orderby)
    {
        $sql .= ' ORDER BY '.$this->orderby;
    }
    else
    {
        // Default order
        $sql .= ' ORDER BY name ';
    }
    // A limit has been set
    if ($this->limit)
    {
        $sql .= ' LIMIT '.(int) $this->limit;
    }

    // Wrap this in an try/catch block just in case something goes wrong
    try
    {
        // Execute the query
        $sth = ThumbsUp::db()->prepare($sql);
        $sth->execute(array($this->name));
    }
    catch (PDOException $e)
    {
        // Rethrow the exception in debug mode
        if (ThumbsUp::config('debug'))
            throw $e;

        // Otherwise, fail silently and just return an empty item array
        return array();
    }

    // Initialize the items array that will be returned
    $items = array();

    // Fetch all results
    while ($row = $sth->fetch(PDO::FETCH_OBJ))
    {
        // Return an item_id => item_name array
        $items[] = array(
            'id' => (int) $row->id,
            'name' => $row->name,
            'url' => $row->url,
            'cat' => $row->cat,
            'closed' => (bool) $row->closed,
            'date' => (int) $row->date,
            'votes_up' => (int) $row->votes_up,
            'votes_down' => (int) $row->votes_down,
            'votes_pct_up' => (float) $row->votes_pct_up,
            'votes_pct_down' => (float) $row->votes_pct_down,
            'votes_balance' => (int) $row->votes_balance,
            'votes_total' => (int) $row->votes_total,
        );
    }

    return $items;
}

thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:32:48+00:00Added an answer on June 16, 2026 at 8:32 pm

    You can easily modify “get()” to add the desired functionality:

    public function get($cat = null)
    {
        $where = array();
        if ($cat !== null) {
            $where[] = 'cat = '. (int) $cat;
        }
    
        // ... original code ...
    }
    

    Usage:

    $items = ThumbsUp::items()->get(1);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have an autohotkey script which looks up a word in a bilingual dictionary
This could be a duplicate question, but I have no idea what search terms
I have an array which has BIG numbers and small numbers in it. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.