PDA

View Full Version : Code that should work, but doesn't


Mikesta707
01-29-2009, 09:47 PM
Hey, I can't figure out what is wrong with my code. I have tried a bunch of ways to make the code work, but it doesn't.

here is the code:

<?
$sql = mysql_query("SELECT fid FROM facebook WHERE uid='$user_id'");

if (!$sql) {//test if SQL was valid
echo "There was an error";
print mysql_error();
exit();
}

$array = mysql_fetch_array($sql, MYSQL_ASSOC);//mysql_assoc because the array doesn't function properly without it

$i = 1;// array entry number

echo "<h2><fb:name uid='$user_id' possessive='true' useyou='false' /> Stoner Friends</h2><br>";//output. you can ignore this

echo sizeof($array) . "<br>";//just to test how big the array is is.

foreach ($array as $fid) {//my array loop

echo "$i: <fb:name uid='$fid' /><br>";



$i++;//update entry number
}
?>

by the way the stuff that looks like <fb:xxxx /> is FBML, the markup language used for facebook apps

$user_id is set in my config file, and I have even tried making it global. the variable works in every other page i've used it for.
I have tried an @ infront of mysql_fetch_array.
What should output is:
1. friend 1
2. friend 2
3. friend 3

What it is outputting is:
1. friend 1

It gets the right info for the first entry, but doesn't output the rest of the information on my table. I have no clue why. I have tried different types of loops, different variable combination's, and all sorts of stuff. the SQL validity check runs true, so I don't think the SQL is wrong, plus it returns the first row correctly. I really have no clue why this doesn't work at all.

Can anyone else make any sense of my problem? Thanks a lot in advance if anyone can help me or lead me in the right direction.

Mikesta707
01-29-2009, 10:56 PM
nevermind i fixed it