Re: "Compiling" Results from a Query
| From: | Brian T. Allen | Date: | Mon, 09 Oct 2000 19:08:57 +0000 |
| Subject: | Re: "Compiling" Results from a Query | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-19227@lists.php.net to get a copy of this message | ||
Hi,
You need to append information to $compile rather than replacing the current
information.
Use:
$compile .= $idea;
Instead of:
$compile .= $idea;
To add the comma's just check to see if anything is already in there:
if($compile){$compile .= ", ";}
Do that before you add the next $idea and you will end up with the list you
want.
HTH,
Brian
> Hi... I have a form that users check off boxes. The boxes are numbered
> project1, project2, project3, etc. When the form is processed, I want
> those project1, project2, project3, etc. to be compiled into one string so
> it would be something like:
> $compile="$project1, $project2, $project3";
> Then, I can insert these into my database as one field. The problem is
> that the number of projects can be different on each form
> submission... i.e., someone can choose 1 project or 8 if they like... so
> the $compile needs to be dynamically generated. I'm currently pulling all
> the possible projects from the DB, and attempting to compare it to the
> user's input. If it matches, it will be inserted into the DB. Here's
what
> I have so far:
> //connect to DB here
>
> $query="SELECT Task from Tasks where Category='ProjDesc'";
> $result = mysql_query($query,$mysql_link);
> $count="0";
> while ($myrow=mysql_fetch_array($result)){
> $count= ($count + 1);
> $idea="$myrow[0]";
>
> $value="project$count";
>
> if ($$value=="$idea") {
> $compile=$idea;
> }
>
> }
> $sql=INSERT INTO myprojects (number,date,client,project,projecthours)
> VALUES
> ('$number','$date','$client','$compile','$projecthours')";
> $result=mysql_query($sql);
>
> }
>
> The problem is that the $compile only inserts the final project that is
> selected. I know why this is happening, but I don't know how to correct
> it. Any ideas?
>
> Thanks,
> -Ben
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net