checkbox + columns

Helo,
I want to add some columns to display by checkboxes.
Each column would have it's own checkbos, and when is checked, this column
is shown in results (display).
How can I do so in php code ?
Can someone show any examle please ?
regards,
Piotr
piotr [ Do, 18 Mai 2006 10:12 ] [ ID #1320203 ]

Re: checkbox + columns

This seems to work...

<?php

include('path/to/connection/script'); //Connection Script

$table="table_name"; //Your table
$field= $_POST['FIELD']; //The fields submitted by the form below

if ($field)
{
$fields = implode($field, ","); //Proabably too crude but works for
now
$query = "SELECT $fields FROM $table;"; //The resulting query
$result = mysql_query($query) or die ("Couldn't execute query.");
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo $row[$fields]; //Show the results
}
}

?>
//The 'values' and 'Checkbox descriptions' below could both be
dynamically generated but,
//in any event, the 'values' must match your table's column names.
<FORM METHOD="POST" ACTION="<?=$self?>">
<INPUT TYPE=checkbox NAME=FIELD[] value=field1>Checkbox 1<br>
<INPUT TYPE=checkbox NAME=FIELD[] value=field2>Checkbox 2<br>
<INPUT TYPE=checkbox NAME=FIELD[] value=field3>Checkbox 3<br>
<INPUT TYPE="submit" NAME="submit">
</FORM>
zac.carey [ Fr, 19 Mai 2006 17:34 ] [ ID #1321687 ]

Re: checkbox + columns

It works, but it only can view one column at a time in a results...
Is there a posability to view for examle 2 or 3 collumns at one time ?
regards,
piotr

Uzytkownik "strawberry" <zac.carey [at] gmail.com> napisal w wiadomosci
news:1148052883.690003.21170 [at] j55g2000cwa.googlegroups.com...
> This seems to work...
>
> <?php
>
> include('path/to/connection/script'); //Connection Script
>
> $table="table_name"; //Your table
> $field= $_POST['FIELD']; //The fields submitted by the form below
>
> if ($field)
> {
> $fields = implode($field, ","); //Proabably too crude but works for
> now
> $query = "SELECT $fields FROM $table;"; //The resulting query
> $result = mysql_query($query) or die ("Couldn't execute query.");
> while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
> {
> echo $row[$fields]; //Show the results
> }
> }
>
> ?>
> //The 'values' and 'Checkbox descriptions' below could both be
> dynamically generated but,
> //in any event, the 'values' must match your table's column names.
> <FORM METHOD="POST" ACTION="<?=$self?>">
> <INPUT TYPE=checkbox NAME=FIELD[] value=field1>Checkbox 1<br>
> <INPUT TYPE=checkbox NAME=FIELD[] value=field2>Checkbox 2<br>
> <INPUT TYPE=checkbox NAME=FIELD[] value=field3>Checkbox 3<br>
> <INPUT TYPE="submit" NAME="submit">
> </FORM>
>
piotr [ Mi, 24 Mai 2006 13:49 ] [ ID #1331145 ]

Re: checkbox + columns

I got the answare:
You just have to put another loop to review the table like that:

while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
foreach ($field as $key) {
echo "<br>" . $row[$key]; //Show the results
}
}



Użytkownik "Piotr" <kefas [at] smk.gda.pl> napisał w wiadomości
news:e51h86$1qf$1 [at] news.task.gda.pl...
> It works, but it only can view one column at a time in a results...
> Is there a posability to view for examle 2 or 3 collumns at one time ?
> regards,
> piotr
>
> Uzytkownik "strawberry" <zac.carey [at] gmail.com> napisal w wiadomosci
> news:1148052883.690003.21170 [at] j55g2000cwa.googlegroups.com...
>> This seems to work...
>>
>> <?php
>>
>> include('path/to/connection/script'); //Connection Script
>>
>> $table="table_name"; //Your table
>> $field= $_POST['FIELD']; //The fields submitted by the form below
>>
>> if ($field)
>> {
>> $fields = implode($field, ","); //Proabably too crude but works for
>> now
>> $query = "SELECT $fields FROM $table;"; //The resulting query
>> $result = mysql_query($query) or die ("Couldn't execute query.");
>> while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
>> {
>> echo $row[$fields]; //Show the results
>> }
>> }
>>
>> ?>
>> //The 'values' and 'Checkbox descriptions' below could both be
>> dynamically generated but,
>> //in any event, the 'values' must match your table's column names.
>> <FORM METHOD="POST" ACTION="<?=$self?>">
>> <INPUT TYPE=checkbox NAME=FIELD[] value=field1>Checkbox 1<br>
>> <INPUT TYPE=checkbox NAME=FIELD[] value=field2>Checkbox 2<br>
>> <INPUT TYPE=checkbox NAME=FIELD[] value=field3>Checkbox 3<br>
>> <INPUT TYPE="submit" NAME="submit">
>> </FORM>
>>
>
>
piotr [ Mi, 24 Mai 2006 14:30 ] [ ID #1331146 ]

Re: checkbox + columns

This might look nicer... (well, I think so anyway ;-) )

echo "<table>";
while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
{
echo "<tr>";
foreach ($field as $key) {
echo "<td>" . $row[$key]."</td>"; //Show the results
}
echo "</tr>";
}

}
echo "</table>";
zac.carey [ Mi, 24 Mai 2006 22:48 ] [ ID #1331152 ]
PHP » alt.php.sql » checkbox + columns

Vorheriges Thema: query efficiency
Nächstes Thema: excluding...