Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
Help me fix this... Details »»
Help me fix this...
Version: , by leon2u leon2u is offline
Developer Last Online: Sep 2004 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 01-13-2003 Last Update: Never Installs: 0
 
No support by the author.

Hai I have made a form on my forum
http://www.inventorusers.nl/prijsvraag.php

But now i want that all users can only send once the form and if they do it a seconde that they will be redirected to a template.

I tried this programming but does not work...I have created a table called prijsvraag en this has a userid en voted column
I want to look in the database if a userid has already voted and if so then they get an already voted form. If not then they can send the from and their userid will be inserted in the database.
So what I need is that the current logged in user will be checked with the userid in the database that has already send the form.
For the total code look the attachment!

THIS IS THE CODE FOR CHECKING but does not work what is wrong???

$prijsvraaginfo=$DB_site->query("SELECT userid FROM prijsvraag WHERE gestemd=1");
while($array=$DB_site->fetch_array($prijsvraaginfo)){
$userids=$array['userid'];
}
if (in_array ($bbuserinfo[userid], $userids)){eval("dooutput(\"".gettemplate('contact _gestemd')."\");");}
else{

Download Now

File Type: (21.4 KB, 7 views)

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 01-14-2003, 07:39 AM
appalcore.org appalcore.org is offline
 
Join Date: Nov 2001
Location: Richmond, KY
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

just a quick glance, but i think you may need to change the line that says
Code:
$userids = $array['userid']
to
Code:
$userids[] = $array['userid']
That way the $userids are actually an array.
Reply With Quote
  #3  
Old 01-14-2003, 01:43 PM
leon2u leon2u is offline
 
Join Date: Mar 2002
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It did the trick!!! Thanx but what does it exactly and why did the other not work? So what is the difference between $userid en $userid[]?

Thanx ....
Reply With Quote
  #4  
Old 01-14-2003, 08:26 PM
appalcore.org appalcore.org is offline
 
Join Date: Nov 2001
Location: Richmond, KY
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$userid creates a variable..and then everytime you were cycling through the results, you were replacing the previous entry you put into it.

by using $userids[], you are creating an array, with $array['userid'] being pushed onto the end of the array.

You might also wanna think about rewriting your code. instead of getting all the userids and putting them in an array, just check the database against that userid, like
Code:
if ($voted = $DB_site->query_first("SELECT * FROM prijsvraag WHERE userid=$bbuserid")) {
  // Display already voted code
} else {
  // Display not voted code
}
This saves you the time of cycling through all the userids and simply checks to see if there's an entry in the database already for their userid.

hope that helps

-john
Reply With Quote
  #5  
Old 01-14-2003, 08:41 PM
leon2u leon2u is offline
 
Join Date: Mar 2002
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well I am quite now to PHP and sometimes I use a hack from here and read code from the forum and the hack to understand what it exactly does. Well I try to retrace it...do you know a good site for PHP-coding?

I tried the above one also but did not work...but I think I understand it now....you can check the database directly by assigning a query to a variabel with in one result the logged in user is in the database then it is true or else false.

You could also use a fetch_array and then assing a variabele array like userid[] which fills an array of information out of the database...

This is correct or not?

Yours is much faster indeed but my database is very small for 150 users.

Thanx for your effort!
Reply With Quote
  #6  
Old 01-14-2003, 08:49 PM
appalcore.org appalcore.org is offline
 
Join Date: Nov 2001
Location: Richmond, KY
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah, the idea you have is correct


(the query_first function in the vB queries the database and automatically grabs the first result row as an array, so you skip the fetch_array step. this is especially handy when you're only expecting one result set, i.e., they voted or they didn't)
Reply With Quote
  #7  
Old 01-14-2003, 09:43 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally posted by appalcore.org
PHP Code:
if ($voted $DB_site->query_first("SELECT * FROM prijsvraag WHERE userid=$bbuserid")) { 
You should use $bbuserinfo[userid] and not $bbuserid to be safe, if the user disables cookies then they can submit the form as many times as they want. Also if using $bbuserid a check should be done to see if its set, otherwise your get DB errors if it isn't.
Reply With Quote
  #8  
Old 01-14-2003, 09:51 PM
leon2u leon2u is offline
 
Join Date: Mar 2002
Posts: 87
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

$prijsvraaginfo=$DB_site->query("SELECT userid FROM prijsvraag WHERE gestemd=1");
while($array=$DB_site->fetch_array($prijsvraaginfo)){
$userids[]=$array['userid'];
}
if (in_array ($bbuserinfo[userid], $userids)){eval("dooutput(\"".gettemplate('contact _gestemd')."\");");}
else{

The above was the first solution taken so this should be better then?
Reply With Quote
  #9  
Old 01-15-2003, 12:57 PM
NTLDR's Avatar
NTLDR NTLDR is offline
Coder
 
Join Date: Apr 2002
Location: Bristol, UK
Posts: 3,644
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

PHP Code:
if ($bbuserinfo[userid]!=0) {
    if (
$voted $DB_site->query_first("SELECT * FROM prijsvraag WHERE userid='$bbuserinfo[userid]'")) {
      
// Display already voted code
    
} else {
      
// Display not voted code
    
}

Would be the best method IMO.
Reply With Quote
Reply


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 01:18 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.04661 seconds
  • Memory Usage 2,307KB
  • Queries Executed 25 (?)
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
  • (3)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (8)postbit
  • (1)postbit_attachment
  • (9)postbit_onlinestatus
  • (9)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_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete