Setting variables using a while loop
Posted: Fri Jan 14, 2011 8:26 am
Now I'm not sure if I have run into a wall because I do't understand enough PHP, SQL or am simply approaching the problem completely wrong. A rough hack of the code I am using is:
so if I was to
It would return:
So my problem is setting $users and $post. I can use a while loop such as
to return the string:
harry, sally, betty, jim
The core of my question is whether it is possible to use the while loop to set the $user variable? Is there a php function I am unaware of yet?
Thanks
Code: Select all
$users = "harry, sally, betty, jim";
$post = " ' \". $_POST['harry'] . \" ',' \" . $_POST['sally'] . \" ',' \" . $_POST['betty'] . \" ',' \" . $_POST['jim'] . \" ' ";
$query = "INSERT INTO groups (" . $users . ") VALUES (" . $post . ")";Code: Select all
echo $query;Code: Select all
$query = "INSERT INTO groups (harry, sally, betty, jim) VALUES (' ". $_POST['harry'] . " ',' " . $_POST['sally'] . " ',' " . $_POST['betty'] . " ',' " . $_POST['jim'] . " ')Code: Select all
$users1 = "SELECT users FROM people WHERE " . $_COOKIE['user'] . " = '1'";
$users1_list = mysql_query($users1);
while ($show_user = mysql_fetch_assoc($users1_list)) {
echo $show_user['user_list'] . ", ";
}harry, sally, betty, jim
The core of my question is whether it is possible to use the while loop to set the $user variable? Is there a php function I am unaware of yet?
Thanks