fallenangel1983 Posted April 1, 2008 Share Posted April 1, 2008 Hey all. im having a small difficulty with this question. say im trying to get a specific ID from a table...lets call it tablename ID NAME 1 GEOFF 2 ANDY 3 BOB so to try and get the specific ID for BOB the mysql would be: $sql="SELECT ID FROM tablename WHERE NAME='bob'"; $result=mysql_query(sql); My question is this: HOW do i then save this ID i have selected into a PHP variable? i.e. i want to save it as a variable named $bobID and so when i write... echo "$bobID"; it reads 3 Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/ Share on other sites More sharing options...
uniflare Posted April 1, 2008 Share Posted April 1, 2008 give us the code Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/#findComment-506730 Share on other sites More sharing options...
fallenangel1983 Posted April 1, 2008 Author Share Posted April 1, 2008 sorry to ask but i dont understand. what code do you want. my ACTUAL table is quite large with a few bits of data. i am unsure of what code it is you require Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/#findComment-506732 Share on other sites More sharing options...
paul2463 Posted April 1, 2008 Share Posted April 1, 2008 <?php $sql="SELECT ID FROM tablename WHERE NAME='bob'"; $result=mysql_query(sql) or die ("error in query ". mysql_error()); $row = mysql_fetch_assoc($result); $bobid = $row['ID']; echo $bobid; ?> Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/#findComment-506733 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 <?php //databse conection $sql="SELECT ID FROM tablename where NAME='bob'"; $result=mysql_query($sql)or die(mysql_error()); while($result=mysql_fetch_assoc($result)){ $bobid=$result['ID']; } echo $bobid; ?> Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/#findComment-506734 Share on other sites More sharing options...
fallenangel1983 Posted April 1, 2008 Author Share Posted April 1, 2008 fantastic cheers guys. thanx verymuch Link to comment https://forums.phpfreaks.com/topic/99033-phpmysql-variable-question/#findComment-506736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.