The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
#1
|
|||
|
|||
Making my own plugin, starting from scratch, some PHP questions (my ongoing adventure
** Hopefully this thread can become a resource for other newbies who want to learn how to do some PHP coding in relation to a vB hack **
Hey everyone, I've been a user here for a while now downloading the great plugins we have in this community. Now I need something custome but couldnt find anyone to take on the project, so I figured, what the hell.. I'll try to make one myself. Now to begin with, I have no knowledge of PHP whatsoever, but i'm not a total idiot, and a pretty quick learner.. I also have general experience with coding from the old basic, then C++ days so I know the general concepts, but not the specific calls anymore. I've been furiously reading the tutorials from the sites that have been generously stickied in this subforum.. but as always, the best way to learn is to learn by doing, so i've started on my project. Now with that background out of the way, I've started on my voyage to making this custom script. It has many stages, but I will try to build it step by step. What my script generally will do in the end will be to take data about a certain user (data would be the users name, user start date and a user end date) and then do some functions based on whether or not todays date matches the pre-definined user start date and end-date. As I dont want to mess with my databse and its tables, I decided to make a simple text file with the information as such: UserName, Start Date, End Date UserName, Start Date, End Date UserName, Start Date, End Date First thing for me was to poll todays date, which I have been able to do, yay! Second is to poll data from the text file. I've been able to pull the data using this call: PHP Code:
Thanks for any thoughts or answers! |
#2
|
||||
|
||||
PHP Code:
file() takes the first parameter, and returns an array containing all of the lines. Then, I created an array which I will load with all the user data... foreach is a loop. For each (array) $lines, set $line equal to that row. I then add a new row the the $users array, containing an array for that current user. Using explode(), you can take a string, and turn it into an array, using the first parameter as a delimiter, and the second as the source array. I used the function trim() on $line because the file() function does not get ride of the whitespace (usually a newline) after each line. After the loop is complete, return the final array. Here is how my array looked, based off this data: Code:
SirAdrian, today, tomorrow Bob, Jan 1st, Feb 1st Jeff, Next Year, in two years Code:
Array ( [0] => Array ( [0] => SirAdrian [1] => today [2] => tomorrow ) [1] => Array ( [0] => Bob [1] => Jan 1st [2] => Feb 1st ) [2] => Array ( [0] => Jeff [1] => Next Year [2] => in two years ) ) |
#3
|
|||
|
|||
Awesome, thanks for the help
Looks like I'm thru step #2 with your help. Now to learn how to properly access the data... i'm trying to do echo $users[0]; but that doesnt work obviously.. My next step is to do an if->then check with the data in my new array (thanks to adrian), how do I properly access the data to do that? What I mean is what is the syntax to pull one piece of specific data out? Thanks! |
#4
|
||||
|
||||
Do you mean like "$db->query(SELECT * FROM tablename WHERE condition = '1')"?
|
#5
|
||||
|
||||
Foreach is very useful again (and in this case, all the loops are really)...
I would do something like this: PHP Code:
Edit: echo $users[0] won't work because it is an array. It will just display "Array". To display anything, you will have to know the exact value you are searching for (or use a loop, which goes through them all). An example would be PHP Code:
@acidburn: the data is in a text file, so queries are no good here. |
#6
|
|||
|
|||
Quote:
FOr now I put in echo commands just to see if it was working so far, I will now replace those with the actual function I want it to do, which has to do with changing the usergroupd of that user... This will take a bit more research PHP Code:
Now on to Stage 3.. Now that this script effectivly checks the user list from a text file and checks the date against todays date, it then effectivly sorts out whos date matchs todays date. (note in previous posts I was using actual usernames, now I will swith to userid #s to keep things simple for now.. so $user is now a number instead of a name) Now I have it calling a function called promote() which will take that user and move him from his current usergroup to usergroup #9 I'm using this call: PHP Code:
|
#7
|
|||
|
|||
To tell your script which database to connect to do the following.
At the beginning of your file add: Code:
include('config.php'); Code:
<? $dbuser = "your database username"; $dbpass = "your database password"; $db = mysql_connect("localhost", $dbuser, $dbpass); $dbname = "name of your database"; ?> |
#8
|
|||
|
|||
Thanks very much, I will try that in a second.
I also found this: require_once('./global.php'); does that do the same thing ? |
#9
|
|||
|
|||
I'm not sure what global.php does to be honest but its not the DB configuration data.
The database file that VB uses is /includes/config.php Sorry... I said invision before for some weird reason! |
#10
|
|||
|
|||
This is a great group of ppl we have here so far, I just took a break from coding for a few mins and I just realized how far I've gotten with this script from not knowing anything a few hours ago. I cant say thanks enought to everyone so far.. I cant wait to see this script to completion and hopefully others can use this info when starting their own scripts from scratch.
:banana: :banana: |
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|