Jump to content

[SOLVED] Taking info from a query and making it a variable


SEVIZ

Recommended Posts

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!

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;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.