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

  • SEARCH
  • Home
  • 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 9228199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:15:52+00:00 2026-06-18T05:15:52+00:00

I want to make a function that selects every field with a specific criteria.

  • 0

I want to make a function that selects every field with a specific criteria. So basically I want to click on a link and let some part of that link tell my php function what the criteria for the selection is.

I have a list of links like this:

<li><a href="category.php?category=cat1">Cat1</a></li>
<li><a href="">Cat2</a></li>
<li><a href="">Cat3</a></li>
<li><a href="">Cat4</a></li>
<li><a href="">Cat5</a></li>

The part of the link is .php?category=criteria. How can I send this information to my function and use it to select the fields?

This is the function I have:

public function get_by_category ($cat) {
  $cat = $_GET['category'];
  $sql = $this->db->prepare("SELECT * FROM Content WHERE category=?");
  $sql->bindParam(1, $cat);
  $sql->execute();

  while ($row = $sql->fetch()) {
    echo $row['Title'];
  }
}

The result is nothing, no errors etc. it doesn’t know how to get the criteria because I don’t know how to direct the criteria to it. How can I make this work? It’s important that I could specify the criteria through the link.

  • 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-18T05:15:53+00:00Added an answer on June 18, 2026 at 5:15 am

    Using PDO with named parameters usually works:

    public function get_by_category ($cat) {
      $cat = $_GET['category'];
      $sql = $this->db->prepare("SELECT * WHERE category=:category");
      $sql->bindParam("category", $cat);
      $sql->execute();
    
      while ($row = $sql->fetch()) {
        echo $row['Title'];
      }
    }
    

    You can see what SQL is being executed by placing a print $sql->fullStmt to inspect the prepared statement before it gets send to SQL.

    Update: in order to see PDO exceptions, you can try-catch them:

    public function get_by_category ($cat) {
      $cat = $_GET['category'];
      try {
        $sql = $this->db->prepare("SELECT * WHERE category=:category");
        $sql->bindParam("category", $cat);
        $sql->execute();
      }
      catch (PDOException $e) {
        print $e->getMessage();
      }
    
      while ($row = $sql->fetch()) {
        echo $row['Title'];
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make a function that automatically turns every Math function global example:
Let's imagine I want to make a templated function that returns the first element
I want to make a function that takes an entered value and converts it
I want to make a function that is always running in xcode similar to
I have a PHP function that I want to make available publically on the
I want to make a function in standard ml that checks if a tree
Let me describe the thing that I want to accomplish: I basically want to
i am trying to make a function that will add a video on some
What i want to do is that the user selects some fields on a
I want to make a function to determine if a user, whose ID is

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.