Re: Assigning a Value (Re-Explained)
| From: | Philip Olson | Date: | Mon, 14 Apr 2003 01:24:46 +0000 |
| Subject: | Re: Assigning a Value (Re-Explained) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-143700@lists.php.net to get a copy of this message | ||
> I have a multi-table database, I have a form that creates a new record for
> one table yet updates a record in another table.
So the contents of this form provides information for the
completion of two SQL queries, okay.
> In the form if the person types in "yes" for the completed field, I need PHP
> to convert yes to a "1" else it will convert it to a "0"
Okay, so you have something like this in you form:
<input type="text" name="completed">
And you require they type 'yes', let's try this:
// Let's define $completed
if (strtolower(trim($_POST['completed'])) === 'yes')) {
$completed = 1;
} else {
$completed = 0;
}
> the table that uses the numbering system keeps track of the completed tasks.
> so this number will increase from time to time.
>
> Here is what I am looking at doing when a person enter in the word "yes"
>
> $addcompleted=$Row[total_completed]+$Array[completed_today]
>
> Then in the Update portion of the script have:
> ..... SET total_completed='$addcompleted' WHERE ..........
So this is keeping a running toll of completed somethings for
something? You can (and should) use SQL for this addition, let's
rewrite the example again:
// This code is just an example!
if (strtolower(trim($_POST['completed'])) === 'yes')) {
$sql = "UPDATE foo SET total_completed = total_completed+1
WHERE something = somethingelse";
if (!mysql_query($sql)) {
$log[] = "Could not run update query ($sql) : " . mysql_error();
}
} else {
echo "You didn't complete it! :(";
}
> any help and explanation would be greatly appreciated, I guess I just don't
> understand the How and Why of the function
Hope the above helps. How and Why of what function?
Regards,
Philip