Jump to content

Getting a single value from a result

Recommended Posts



If my table is

Batman  Human  45

Superman Alien  33


How do I display Superman's race and age?


Currently I have

$sql_statement = "SELECT * FROM heroes";
$toons=mysqli_query($mysql_DB, $sql_statement);

while($toons = mysqli_fetch_array($results, MYSQLI_ASSOC)) {
echo name;

 But this shows all the results where I only want one.  Yes I know I could do a "WHERE name = Superman" in the statement but I want the whole table loaded in as I wish to use the other name (Batman) in another part of the program.

Please note that this is only a sample data table, the real table is a lot bigger (42k rows so I can't simply do a new sql call each time).

Edited by cliftonbazaar

Share this post

Link to post
Share on other sites

I have no idea what you're trying to do there. First you want one record, then you want two records, and then you talk about loading 42,000 records all at once, which sounds rather insane.


Forget about SQL for now and give us the full picture. What do you want to do with what information? How is the resulting page supposed to look like?

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.