siwelis Posted May 25, 2007 Share Posted May 25, 2007 $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? Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/ Share on other sites More sharing options...
pikemsu28 Posted May 25, 2007 Share Posted May 25, 2007 $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. Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-261749 Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 Also, you don't echo $result when retreiving results from a query. See the mysql_fetch_* functions, mysql_fetch_row() in particular. Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-261764 Share on other sites More sharing options...
siwelis Posted May 25, 2007 Author Share Posted May 25, 2007 $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 Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-261769 Share on other sites More sharing options...
siwelis Posted May 25, 2007 Author Share Posted May 25, 2007 $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. Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-261774 Share on other sites More sharing options...
Wildbug Posted May 25, 2007 Share Posted May 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-261783 Share on other sites More sharing options...
fenway Posted May 30, 2007 Share Posted May 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52985-solved-find-what-var1-equals-in-a-table/#findComment-264869 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.