Ok i see the prob.. I can't return the array and the contents if its put into a var.. it will not return or echo the var..
Any other ideas?
syntax error
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
function list_f() {
$sql = "SELECT f FROM users WHERE user='$name'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$friends = $row['f'];
$list_friends = explode(',', $friends );
$string = "";
for ($i=0; $i<7; $i++)
{
$string .= $list_friends[$i].'<br />';
}
return $string;
}By the way, where does $name come from. To use outside variables within a function you must pass it with the function name. For example
Code: Select all
function list_f($name)-
pinehead18
- Forum Contributor
- Posts: 329
- Joined: Thu Jul 31, 2003 9:20 pm
yeah i don't think this is ever going to work.. I've tried everything you guys have asked even did some trouble shooting and it will not output anything when i call the function I'll show you what i have now .
$output .="html html";
$output .= list_friends($name);
$output .= "rest of html";
this will not return any information where i call it.. In fact when i call it, it does nothing. What it is suppsoe to do is list all the contents from the field/array in the db.
thanks
anthony
Code: Select all
function list_friends($name) {
$sql = "SELECT friends FROM users WHERE user='$name'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$friends = $row['friends'];
$list_friends = explode(',', $friends);
for ($i=0; $i<7; $i++) {
$friends = $list_friends[$i];
}
return $friends;
}$output .= list_friends($name);
$output .= "rest of html";
this will not return any information where i call it.. In fact when i call it, it does nothing. What it is suppsoe to do is list all the contents from the field/array in the db.
thanks
anthony
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
-
pinehead18
- Forum Contributor
- Posts: 329
- Joined: Thu Jul 31, 2003 9:20 pm
It works great thank you for your help.. Learning alot here today. I do have one final question, something came up that i did not expect. Do you see the loop? It runs 7 times no matter what it is really cuasing a problem mainly becuase it takes up alot of extra space. waht i want to accomplish is i just want it to show the vars in the array up too 7 times and after 7 times don't display anymore. Do i just take out the for loop and use a while loop.. Or even just pull it from the db and use a limit? How might i go about that?
thank you
Anthony
thank you
Anthony
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
function list_f() {
$sql = "SELECT f FROM users WHERE user='$name'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
$friends = $row['f'];
$list_friends = explode(',', $friends );
$string = "";
for ($i=0; $i >= count($list_friends); $i++)
{
$string .= $list_friends[$i].'<br />';
}
return $string;
}