xwishmasterx Posted April 14, 2011 Share Posted April 14, 2011 Am unalbe to figure out how to get a value from a database and use it later on. If I have a simple query: $query2 ="SELECT team_id FROM vtp_members WHERE id=".$_GET['r']." "; $result2 = mysql_query($query2); How can I "store" the value to use later one? can I do something like: $teamvalue = $result2? (there will only be one value /result) Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/ Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 You still need to fetch the data from $result2, using either mysql_fetch_array or mysql_fetch_assoc. For the rest, what do you mean by 'store'? Where do you want to use the variable? Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/#findComment-1201569 Share on other sites More sharing options...
xwishmasterx Posted April 14, 2011 Author Share Posted April 14, 2011 I need to do and UPDATE right after and need that value in the WHERE clause. if I have this: $query2 ="SELECT team_id FROM vtp_members WHERE id=".$_GET['r']." "; $result2 = mysql_query($query2); $numrows2 = mysql_num_rows($result2); if($numrows2 == '1') { while($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { what can I then use to UPDATE xxxxx WHERE team_id ='$result2???' or how should that look? Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/#findComment-1201572 Share on other sites More sharing options...
cyberRobot Posted April 14, 2011 Share Posted April 14, 2011 You would use the $row variable created from the mysql_fetch_array() call. For example: $row['team_id'] Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/#findComment-1201575 Share on other sites More sharing options...
KevinM1 Posted April 14, 2011 Share Posted April 14, 2011 You need something like: $query2 = "SELECT team_id FROM vtp_members WHERE id = {$_GET['r']}"; $result2 = mysql_query($query2); $numrows2 = mysql_num_rows($result2); if ($numrows2 == 1) { $row = mysql_fetch_assoc($result2); $query3 = "UPDATE xxxxx SET yyyyy = zzzzz WHERE team_id = {$row['team_id']}"; // etc. } Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/#findComment-1201576 Share on other sites More sharing options...
cyberRobot Posted April 14, 2011 Share Posted April 14, 2011 As Nightslyr suggested, if "id" is the primary key and/or only gives one record every time you don't need the while loop. Quote Link to comment https://forums.phpfreaks.com/topic/233719-how-to-get-value-too-use-for-later-on/#findComment-1201577 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.