vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Checkboxes in php (https://vborg.vbsupport.ru/showthread.php?t=34818)

Lesane 02-05-2002 07:39 PM

I try to determine if a variable is set and if so then the checkbox is selected. I tried it with this code but it dont works, when i execute it then all the checkboxes are checked while only one field is filled with aw so 1 checkbox has 2 be checked instead of all :(

PHP Code:

$result mysql_query("SELECT aw,awardsid,name, url FROM award");
         while (
$award mysql_fetch_array($result)) {
         
         if (Isset(
$award[aw]))
         
$lala="checked";
         else
         
$lala="";
         
       echo 
"<tr><td><input type='checkbox' name='aw[$award[awardsid]]' value='$award[awardsid]'";
          if (
$aw) {
          echo 
"selected $lala>$award[name]</td><td nowrap>";
          } else {
          echo 
$lala>$award[name]</td><td nowrap>";
          }
       echo 
"<img src=\"$award[url]\">&nbsp;&nbsp;&nbsp;</td>";
     } 

As you can c, i'm using this code to check if its set or not:

PHP Code:

if (Isset($award[aw]))
         
$lala="checked";
         else
         
$lala=""


Hope someone can help me out, any help is appreciated.

XiXora 02-05-2002 09:49 PM

i've laready asked 5 times for this :( looks like we'll have to wait to v 3 to me :(

Admin 02-06-2002 06:27 AM

Try this...
PHP Code:

$result mysql_query("SELECT aw,awardsid,name,url FROM award");
while (
$award mysql_fetch_array($result)) {
  if (
$award['aw']!='')
    
$checked='checked';
  else
    
$checked='';
         
  echo 
"<tr>
        <td>
        <input type=\"checkbox\" name=\"aw[
$award[awardsid]]\" value=\"$award[awardsid]\" $checked>
        
$award[name]
        </td>
        <td nowrap>
        <img src=\"
$award[url]\">&nbsp;&nbsp;&nbsp;
        </td>
        </tr>"
;



Lesane 02-06-2002 06:47 AM

Thanks for the replies

@firefly, that didnt worked. I tried this code and it works now :up:

PHP Code:

$lesane=$award[aw];
          if(
$lesane == "$award[awardsid]") {         
         
$lala="checked";
         } else {
         
$lala="";
         } 

Now i'm almost done with the hack but i'm stuck when you uncheck a checkbox, then the row wont be updated. The variable is still in the database. Lets say i have a award called lesane and it has currently the variable 1 in the database, now i want to uncheck it and when i click on submit then lesane must be updated as empty. Hope u can follow me and can help me out with this

Admin 02-06-2002 06:51 AM

You need to set a hidden field saying the field WAS there, and then in the parsing if the variable doesn't exists (=checkbox is not checked) remove the row.

Lesane 02-06-2002 07:02 AM

Cool, thanks Firefly. I gonna test that out.

Be Right Back :D

Lesane 02-06-2002 09:06 AM

i'm going crazy :D

i'm using the following code:

PHP Code:

<?php

include("config.php");

if (isset(
$submitok)) {


if (
$delete) { 
foreach(
$delete as $val) {
$query "DELETE FROM award WHERE aw='$uid'"
$result mysql_query($query) or die("SELECT Error: " mysql_error() . " in Query: $miet"); 
 }
if(
$result) {
print (
"deleted");
} else {
print (
"not gedeleted");
}
}


    foreach(
$aw as $val) {
    
$lala="UPDATE award SET aw='$val' WHERE awardsid='$val[awardsid]'";
    
$result mysql_query($lala) or die("SELECT Error: " mysql_error() . " in Query: $query");
       }
if(
$result) {
print (
"updated");
} else {
print (
"not updated");
}

    }

else {


?>


<center>
<h3>Awards
<hr width="75%" color="#00AAFF">
</h3>
</center><br>
<form action="<?PHP $PHP_SELF ?>">
<table width="100%" cellspacing="0" cellpadding="5" border="1">
 <tr>
  <td>Awardsname</td>
  <td>Button</td>
 
 </tr> 

<?php

include("config.php");

$result mysql_query("SELECT aw,awardsid,name, url FROM award");
         while (
$award mysql_fetch_array($result)) {
         
$lesane=$award[aw];
          if(
$lesane == "$award[awardsid]") {         
         
$lala="checked";
         } else {
         
$lala="";
         }
         
       echo 
"<tr><td><input type='checkbox' name='aw[$award[awardsid]]' value='$award[awardsid]'";
          if (
$aw) {
          echo 
"selected $lala>$award[name]</td><td nowrap>";
          } else {
          echo 
$lala>$award[name]</td><td nowrap>";
          }
       echo 
"<img src=\"$award[url]\">&nbsp;&nbsp;&nbsp;</td>";
     
     if(!
$award[aw]) {
     
$uid="aw[$award[awardsid]]";
     } else {
     
$uid=""
     }
     } 
 echo 
"<br><tr><td colspan=2 align=center>";
 echo 
"<br><input type='hidden' name='delete[]' value='$uid'>";
echo 
"<br><br><input type='submit' name='submitok' value='Submit'>";
echo 
"</td></tr></table></form>";

    }
?>

I have currently 2 awards in the database

1. Awards name with the awardsid 9 and aw is also 9
2. Lesane with the awardsid 13 and aw is empty (means not checked)

So when i execute the script then i c awards name selected and lesane is not selected and if i check the code by <input type =hidden then i c:

<input type='hidden' name='delete[]' value='aw[13]'>

so thats right, lesane is not selected and have the id 13.

Now i'm totally confused because when i click on submit then it deletes lesane totally and when i uncheck the award with the name "awards name" then that aw is not gonna deleted because only the input type = hidden was lesane :(

So my questions are:

Whats the delete query to delete only the aw row from awards where awardsid=?
&
How is it possible to delete the aw row from the award called "Awards Name" when i uncheck him?


I hope u have a solution :(

badr511 02-06-2002 09:51 AM

working now or not

badr511 02-06-2002 10:07 AM

firefly why ican't download attachment

Lesane 02-06-2002 10:15 AM

No, its still not working.

When i try 2 unselect a checkbox and press on submit then he must delete the variable from that table :?:


All times are GMT. The time now is 03:59 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01982 seconds
  • Memory Usage 1,770KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete