Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #11  
Old 02-07-2002, 03:14 PM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by FireFly
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.
Firefly, could you give me an example?
Reply With Quote
  #12  
Old 02-07-2002, 03:28 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, just talking in general here, but you should get the point.

If you look in the hacks database you will see something like this:
Code:
<tr align="center">
	<td bgcolor="#13486D"><img src="https://vborg.vbsupport.ru/images/folder.gif" align="left"></td>
	<td bgcolor="#1C5780" align="left" valign="top"><font face="verdana" size="2">[high]<input type="checkbox" name="install[34534]" value="yes" checked>[/high] <a href="index.php?s=&action=showhack&hackid=73">List similar usernames when moderating user registration</a></font></td>
	<td bgcolor="#13486D"><font face="verdana" size="2"><a href="https://vborg.vbsupport.ru/member.php?s=&action=getinfo&userid=3771">dlst</a></font></td>
	<td bgcolor="#1C5780" nowrap><font face="verdana" size="1">01-27-02<br><font color="#FF9C58">08:07 PM</font></font></td>
	<td bgcolor="#13486D" nowrap><font face="verdana" size="1">01-27-02<br><font color="#FF9C58">08:07 PM</font></font></td>
	<td bgcolor="#1C5780"><a href="javascript:whoinstalled(34534)"><font face="verdana" size="2">1 user</font></a></td>
	<td bgcolor="#13486D"><img src="https://vborg.vbsupport.ru/images/clear.gif" border="0" alt="0 votes - 0.00 average"></td>
</tr>
[high]<input type="hidden" name="all[34534]" value="1">[/high]
So you can see I put two fields for each hack, one is a part of an array all[], which eventually has all the ID's of the hacks in that page. The value of that field is either 0 or 1. 1 if the user already installed the hack, and 0 if he hasn't.

Then there's the real checkbox, that the user can change. That's part of the install[] array, which holds all the ID's of the hacks the user WANTS to have installed.

And here's a little bit of code from the page itself, that parses the results:
PHP Code:
        while (list($threadid,$was)=each($all)) {
            
$now=$install[$threadid];
            if (
$now=='yes' and $was=='0') {
                
// Here I install the hack!
            
} elseif ($now!='yes' and $was=='1') {
                
// Here I un-install the hack!
            
}
        } 
I'm listing the stuff from the all[] array, that has the ID's of the hacks and the state (installed or not) BEFORE the submit, and put the 1/0 into $was (meaning what WAS the state). Then I'm taking the value of the install[] with the current ID and put it into $now (which represents the state as it NEEDS to be).

And then it's really simple logic! If the hack wasn't installed ($was equals 0) and it SHOULD be now ($now equals yes), then we need to install the hack.
Otherwise, if the hack WAS installed ($was is 1) but the user un-checked the box (so $now is not yes), we need to un-install the hack.
If non of the above is true, it means that the hack is either already installed and the user didn't touch the checbox, or it is not installed but the user didn't check the checkbox neither.

*takes a deep breath*
Did I say I was talking in general?
Reply With Quote
  #13  
Old 02-07-2002, 05:35 PM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Firefly, it works almost 100%.

However one thing: $threadid. Where and how did u defined that one because i get an error:

PHP Code:
WarningVariable passed to each() is not an array or object in user.php on line 280 
I'm not using $threadid but $award[awardsid] for the id.

This is my currently code:

PHP Code:
$awards=$DB_site->query("SELECT aw,awardsid,name,url,userid FROM award");
      while (
$award=$DB_site->fetch_array($awards)) {
         if(
$award[aw] == "$award[awardsid]and $award[userid] == "$user[userid]") {         
         
$lala="checked";
         
$was="1";
         
$kol="yes";
         } else {
         
$lala="";
         
$was="0";
         
$kol="no";
         }    
          echo 
"<tr class='".getrowbg()."'><td><input type='checkbox' name='aw[$award[awardsid]]' value='$kol'";
           echo 
"$lala>$award[name]</td><td nowrap>";
           echo 
"<input type=\"hidden\" name=\"all[$award[awardsid]]\" value=\"$was\">";
           echo 
"<img src=\"$award[url]\">&nbsp;&nbsp;&nbsp;</td>";
         }
     
      while (list(
$award[awardsid],$was)=each($all)) {
            
$now=$aw[$award[awardsid]];
            if (
$now=='yes' and $was=='0') {
                
$kutje='yes';
            } elseif (
$now!='yes' and $was=='1') {
                
$kutje='no';
            }
         } 

Its a little general
Reply With Quote
  #14  
Old 02-07-2002, 05:40 PM
Admin's Avatar
Admin Admin is offline
Coder
 
Join Date: Oct 2023
Location: Server
Posts: 1
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1. What's this $kol crap? The checkbox value is always yes!

2. The whole part where you list the array and do your stuff is AFTER you SUBMIT the form, not while printing it.
Reply With Quote
  #15  
Old 02-07-2002, 06:04 PM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

1.
PHP Code:
if($award[aw] == "$award[awardsid]and $award[userid] == "$user[userid]") {
$kol="yes";
         } else {
$kol="no";
         } 
So kol is yes when the checkbox has a variable.

2.
Quote:
I'm listing the stuff from the all[] array, that has the ID's of the hacks and the state (installed or not) BEFORE the submit
So i thought before the submit

Its working perfect now, thank you for your help Firefly. Appreciated.
Reply With Quote
  #16  
Old 02-07-2002, 07:01 PM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by FireFly
1. What's this $kol crap? The checkbox value is always yes!
You right, its always yes :surprised :stoned:

How did you defined the value yes?
Reply With Quote
  #17  
Old 02-09-2002, 10:42 AM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

firefly, it works perfect if i have just 1 award but when i have more then 1 award then it updates the database only with the last award, it only listening to the last award. So if i have 2 awards then it updates only the 2nd award and ignores the 1st one. Could u help me with this (hopefully) last problem

I have the currently code:

Code before submit:

PHP Code:
$awards=$DB_site->query("SELECT aw,awardsid,name,url,userid FROM award");
      while (
$award=$DB_site->fetch_array($awards)) {
         if(
$award[aw] == "$award[awardsid]and $award[userid] == "$user[userid]") {         
         
$lala=" checked";
         
$was="1";
         
$kol="no";
         } else {
         
$lala="";
         
$was="0";
         
$kol="yes";
         }
          echo 
"<tr class='".getrowbg()."'><td><input type='checkbox' name='aw[$award[awardsid]]' value='$kol'";
           echo 
"$lala>$award[name]</td><td nowrap>";
           echo 
"<input type=\"hidden\" name=\"all[$award[awardsid]]\" value=\"$was\">";
           echo 
"<img src=\"$award[url]\">&nbsp;&nbsp;&nbsp;</td>";
         } 

Code after submit:

PHP Code:
while (list($award[awardsid])=each($all)) {
            
$was=$all[$award[awardsid]];
            
$now=$aw[$award[awardsid]];
            if (
$now=='yes' and $was=='0') {
               
$DB_site->query("UPDATE award SET aw='$award[awardsid]' WHERE userid=$userid and awardsid=$award[awardsid]");
            } elseif (
$now!='yes' and $was=='1') {
                
$DB_site->query("UPDATE award SET aw=0 WHERE userid=$userid and awardsid=$award[awardsid]");
            }
         } 
Reply With Quote
  #18  
Old 02-10-2002, 08:27 AM
Lesane's Avatar
Lesane Lesane is offline
 
Join Date: Oct 2001
Location: The Netherlands
Posts: 1,149
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nevermind, i got it working now :up:
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 11:20 PM.


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.05903 seconds
  • Memory Usage 2,283KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)bbcode_code
  • (6)bbcode_php
  • (3)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete