SEVIZ Posted March 16, 2009 Share Posted March 16, 2009 I have this code: <?php // Make a MySQL Connection mysql_connect("localhost", "___", "___") or die(mysql_error()); mysql_select_db("____") or die(mysql_error()); // Retrieve all the data from the "TECH" table $result = mysql_query("SELECT * FROM tech WHERE ID='".$_POST['tech']."'") or die(mysql_error()); // Print out the contents of the entry while($row = mysql_fetch_array($result)){ echo $row['NAME']. " - ". $row['ID']. " - ". $row['ALLOW']. " - ". $row['TEAM']. " - ". $row['LOCA']; echo "<br />"; } ?> <html> Hello <?php echo $name; ?>! Your tech id is <?php echo $id; ?>. Your allowance is <?php echo $allow; ?>. Your team is <?php echo $team; ?>. Your location is <?php echo $loca; ?>. </html> I want to be able to call NAME, ID, ALLOW, TEAM, and LOCA later in the php page. How can I turn those into a variable to be called later in the php document? I tried $row['ALLOW'] but no dice. Thanks for any tips! Quote Link to comment https://forums.phpfreaks.com/topic/149660-solved-taking-info-from-a-query-and-making-it-a-variable/ Share on other sites More sharing options...
syed Posted March 16, 2009 Share Posted March 16, 2009 Hi SEVIZ The row variable is only local, you will need to create global variables, outside of the while loop. Example. $id=0; $name=""; while($row = mysql_fetch_array($result)){ $name = $row['NAME']; $id = $row['ID']; } print $name; Quote Link to comment https://forums.phpfreaks.com/topic/149660-solved-taking-info-from-a-query-and-making-it-a-variable/#findComment-785934 Share on other sites More sharing options...
SEVIZ Posted March 17, 2009 Author Share Posted March 17, 2009 Thank you very much. Worked as expected! Quote Link to comment https://forums.phpfreaks.com/topic/149660-solved-taking-info-from-a-query-and-making-it-a-variable/#findComment-786360 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.