...

View Full Version : assign to variable



bunny1
03-06-2007, 12:55 PM
I am trying to take data from the database and assign it to a variable but i'm not sure how
this is the code ive been trying

$sql = "SELECT Name FROM Names WHERE Name = 'Peter'";

while($row = @mysql_fetch_array($sql))
{
$var == $row['Name'];
}

thanks

Nightfire
03-06-2007, 01:13 PM
$sql = "SELECT Name FROM Names WHERE Name = 'Peter'";
$query = mysql_query($sql) or die(mysql_error());
while($row = @mysql_fetch_array($query))
{
$var = $row['Name'];
}

chump2877
03-06-2007, 01:15 PM
$sql = "SELECT Name FROM Names WHERE Name = 'Peter'";
$result = mysql_query($sql);

while ($row = mysql_fetch_assoc($result))
{
$var = $row['Name'];
}

JohnDubya
03-06-2007, 02:43 PM
$sql = "SELECT Name FROM Names WHERE Name = 'Peter'";

while($row = @mysql_fetch_array($sql))
{
$var == $row['Name'];
}


Hey bunny! Remember that when you make a query to a DB, you've got to use mysql_query() to actually send the request. And, of course, make sure you're already connected to your database before you make a query.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum