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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:53:40+00:00 2026-06-14T10:53:40+00:00

This question is more on this post . So I want to retrieve the

  • 0

This question is more on this post. So I want to retrieve the number in a certain column. So let’s say the table looks like this:

A | B | C | D | E | F
---------------------
0 | 50| 0 | 0 | 0 | 0

Let’s say the user enters in B, I want to go fetch the current number in the table, which is 50. This is my SQL code:

$link = new PDO('**;dbname=**;charset=UTF-8','**','**');
$stmt = $link->prepare("SELECT MAX(:type) as max FROM table");
$stmt->bindParam(':type', $type);
$stmt->execute();
$used = $stmt->fetch(PDO::FETCH_ASSOC);
$used = $used["max"];

But this is just returning B rather than the number. How do I change my code to get the number? 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-14T10:53:41+00:00Added an answer on June 14, 2026 at 10:53 am
    SELECT MAX(:type) as max FROM table
    

    Assuming :type gets set to “B”, this will be executed as:

    SELECT MAX("B") as max FROM table
    

    The MAX of something with just one value will be that one value, i.e.:

    SELECT "B" as max FROM table
    

    Most likely you want to select the MAX from that column, not the string:

    SELECT MAX(B) as max FROM table
    

    Which you can do like this:

    $stmt = $link->prepare("SELECT MAX($type) as max FROM table");
    

    Obviously, this is vulnerable to SQL injection if $type comes from a user, but if you’re getting a table name from a user, then you’re doing something wrong anyway.

    It’s also possible that your table would make more sense like this:

    type | value
    ------------
    A    | 0
    B    | 50
    C    | 0
    

    And then you could get it with:

    SELECT MAX(value) FROM tableName WHERE type = :type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using jQuery. This is my second post to make my old question more
This question is more or less the same as Restrict Certain Java Code in
ASP.Net MVC3 is cool and all but I have this question more out of
This question is more philosophical than technical. I've trained myself as a web developer
This question is more UI/Design-ish than hard-core programming is. Background: I've been coding in
This question is more about guidance than actually solving my problem: I need to
This question is more a re-insurance than one directly about how to code. As
I had asked this question Adding more attributes to LINQ to SQL entity Now,
I suppose this question is more general than working with COM components. I have
This question might be more apt to programmers.stackexchange. If so, please migrate. I am

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.