![]() |
Help me fix this...
1 Attachment(s)
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{ |
just a quick glance, but i think you may need to change the line that says
Code:
$userids = $array['userid'] Code:
$userids[] = $array['userid'] |
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 .... |
$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")) { hope that helps -john |
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! |
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) |
Quote:
|
$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? |
PHP Code:
|
All times are GMT. The time now is 09:20 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 | |
---|---|
|
|
![]() |
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|