Array issue

Hey Guys,

I’ve an array … This is the code

	
mysql_select_db($database, $connection);
$sql = "SELECT * FROM BAY_Info WHERE BAY_Info.ContID = 2 LIMIT 1";
$result = mysql_query($sql);
$data = array();	
				
while($row = mysql_fetch_assoc($result)) 
	{
		$data[] = $row;
		$title = $data['Title'];
	}

echo $title;

Problem is $title isn’t pulling anything back, and it “should” I’ve got a simlar statement working upon another site and this is in exactly the same context.

Can anyone shed any light into why the “$title” isn’t returning any data. the var is completely blank :frowning:

Any help would be highly appreciated.

Kind Regards
Dan.

$title = $row[‘Title’];

Thankyou AlienDev!

I can’t believe i missed that,

… Fresh eyes and all that

Maybe i should take a break!

Cheers again!

As you are only fetching one row, you needn’t use a loop at all :slight_smile:

mysql_select_db($database, $connection);
$sql = "SELECT * FROM BAY_Info WHERE BAY_Info.ContID = 2 LIMIT 1";
$result = mysql_query($sql);
$data = mysql_fetch_assoc($result);
$title = $data['Title'];
echo $title; 

For development i changed the varible to a 2, so that it was easier for a debug.

But you are quite right if it was a single entry I wouldn’t need a loop. But in this instance I do need the loop.

Cheers thought guys! The speedy reply’s are much appreciated.

/me loves sitepoint! :slight_smile: