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 6974593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:15:28+00:00 2026-05-27T17:15:28+00:00

I am trying to fetch all rows within a MySQL table that have a

  • 0

I am trying to fetch all rows within a MySQL table that have a specific input within a particular column.
Here is my table:

ID  COLOR   LENGTH 
--- ------- ------
19  red     10 
3   green   45 
24  blue    54 
4   red     3 
5   red     11

How would I fetch all the the rows that have "red" as the stored value within the "COLOR" column? Can somebody please help?

I am a newbie to MySQL/PHP, so forgive me if this is a stupid question. I tried looking all over but I could not find an answer to it

  • 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-05-27T17:15:29+00:00Added an answer on May 27, 2026 at 5:15 pm

    Since you’re a newbie, I’d like to recommend proper SQL coding. Name all the columns you need, even if you need all the columns that exist in your table. Avoid using the SELECT * ... approach. Develop good practices and habits as early as today:

    SELECT ID, COLOR, LENGTH FROM table WHERE COLOR = 'red';
    

    A very basic example of how you’d get things done in PHP:

    <?php
    # variables you will need. values below are mere examples only
    $server = 'localhost';
    $database = 'databasename';
    $username = 'username';
    $password = 'password';
    
    # create database connection
    try {
        $pdodb = new PDO('mysql:host='.$server.';dbname='.$database, $username, $password);
        $pdodb->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    } catch (PDOException $ex) {
        printf($ex->getMessage());
        exit;
    }
    
    # use prepared statements, for starters:
    $stmt = $pdodb->prepare("SELECT ID, COLOR, LENGTH FROM table WHERE COLOR = ?");
    $stmt->bindValue(1, 'red')
    $stmt->execute();
    
    # store each row into an array
    $resultset = array();
    do {
        $resultset[] = $onerow; 
    } while ($onerow = $stmt->fetch(PDO::FETCH_COLUMN));
    
    # to test your resultset:
    print_r($resultset); # use this only to display during debugging/testing
    ?>
    

    Here are links to articles that can help you get started:

    net.tutsplus

    phpeveryday

    phpro

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch all rows from a table with a UNIX timestamp in
Im trying to build a query that will fetch all changed rows from a
I'm trying to use a SELECT statement and fetch all rows from a table
I have a table with 6 columns in it, I'm trying to fetch all
I'm trying to query a table, fetch all records, and save the result as
I'm trying to fetch some HTML from various blogs and have noticed that different
I'm trying to fetch rows that are in an array of integers that I
PLATFORM: PHP, mySQL WHAT I HAVE: I have a Database table. Within my application,
PLATFORM: PHP, mySQL & jQuery WHAT I HAVE: I have a Database table. Within
I am trying to list out all records from a database that have not

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.