Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Questions and Supports

Notices

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-11-2017, 12:01 PM
ewe ewe is offline
Member
 
Join Date: Mar 2017
Posts: 8
Gender: Female
Credits: 2,339
ewe is on a distinguished road
Default

I realize this is a very old question but I peeked at your Raffle Mod and noticed it's still using the if statement so I'm sorry if you have already found your answer but in case you haven't (or someone in the future needs the answer) here it is -

You should just be able to do something like this:
PHP Code:
for ($i 1$i <= $chosenOption$i++) {
    
$mysidia->db->insert("raffle_tickets", array("owner" => $mysidia->user->username));

I suspect you may have tried that already and had errors or weird results.

PHP is a loosely typed language and while that is usually convenient it can sometimes cause variables to misbehave and do strange things. Strongly typed languages require you to define what type of variable you're making when you name it. (ex: string, float, int, etc).
  Spoiler: PHP vs Java 
A for loop in Java is an easy way to demonstrate the difference as the code is almost exactly the same.
Code:
for(int i=1; i<11; i++) {
   System.out.println("Count is: " + i);
}


Data from $mysidia->input->post("stuff") behaves like a string but you can't check if $i is less than a string because a string could very well be something like "sheep" and it would be very difficult to count to sheep.

Luckily, it is very easy to turn a string into a number type of variables.
PHP Code:
$chosenOption $mysidia->input->post("myList");
$chosenOption $chosenOption 0
I've found PHP generally sees something like $var = 1; to actually be $var = TRUE; and does not recognize 1 as an integer. FALSE, 0, and '' (empty string) are also all the same thing but NULL is NULL except on a boolean check will return FALSE.

As an aisde, when checking something like the options from a dropdown menu you may be better off using a switch statement instead of a long if-else if-else. I find they're a bit easier to read (as long as you remember to include the break;!) and I believe they're a little less resource intense though that doesn't matter very much here.

Mysidia is written in PHP and PHP has a lot of interesting functions. Two great resources for looking things you need up (besides Google, Google will likely direct you to one of the two if you ask PHP questions and it's a great way to get where you're going faster) are the PHP Manual and W3Schools. I strongly prefer the PHP Manual (the comments are especially helpful) but I have friends who understand the W3School explanations better.
Reply With Quote
 

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 -5. The time now is 05:09 PM.

Currently Active Users: 1686 (0 members and 1686 guests)
Threads: 4,081, Posts: 32,043, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636