Jump to content

[SOLVED] Find what var1 equals in a table


siwelis

Recommended Posts

$var1 = UniqueNumber;

$result = mysql_result(mysql_query("SELECT UniqueName from tab1e_1

WHERE UniqueName = $var1);

echo $result;

 

I'm not sure how to ask this question towards SQL... I'm pretty sure I'm asking it all wrong.

 

In case it helps: I have 4 rows, each with a unique number, and a unique name, I'm trying to figure out how to find the unique name, using the unique ID ($var1).

 

How do I ask this question to MySQL?

Link to comment
Share on other sites

$sql = "select UniqueName from table_1 where UniqueNumber = $var1";

 

this will pull the UniqueName from the table where the UniqueNumber is whatever $var1 is set to.

 

Thank you both very much. I couldn't get that working as exactly stated, but I compared it to some other code and come up with mysql_result(mysql_query(SELECT UniqueName FROM table_1 WHERE UniqueNumber = $var1

Link to comment
Share on other sites

$sql = "select UniqueName from table_1 where UniqueNumber = $var1";

 

this will pull the UniqueName from the table where the UniqueNumber is whatever $var1 is set to.

 

Thank you both very much. I couldn't get that working as exactly stated, but I compared it to some other code and come up with

 

mysql_result(mysql_query("SELECT UniqueName FROM table_1 WHERE UniqueNumber = '$var1'"_,0);

 

and that works! I will be tinkering with mysql_fetch now as well. Thank you Wildbug and pikemsu28!

 

David

 

PS. I accidentially posted this partial comment a moment ago due to a keyboard shortcut I accidentially pressed in Opera. Keyboard shortcuts are my friend- Ever since I heard Windows was originally made so that any action performed using a mouse could be performed using a keyboard as well, they've become intimately close with me. Intimately. Just joking, but I rank them high in both the mouse clicking and time saving departments.

Link to comment
Share on other sites

Yep, mysql_result($result,0) is a great way to fetch a single value.  If your UniqueNumber column is of a numeric type, you won't need those quotes.

Just remember that if you're getting more than one field back, it's not as effecient as getting the entire hash.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.