Jump to content

Search the Community

Showing results for tags 'select'.

More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • RuneLocus
    • News & Announcements
    • Information Booth
    • Website Support
    • Introductions
    • Chat
    • Forum Games
  • RuneScape Development
    • RSPS General
    • RuneScape Private Server (RS2)
    • RuneScape Private Server (503+)
    • RuneScape Private Server (EoC 742+)
  • Other
    • Digital Art
    • Gaming
    • Webdevelopment
    • Computers
  • Marketplace
    • RuneScape Market
    • RSPS Market
    • Others Market
    • Freelance Middleman Services
  • Super Secret Club's Topics

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start



Found 4 results

  1. [CENTER][B][U]MySQL with PHP - The Basics[/U][/B][/CENTER] Incase you missed it, here's the introduction/part 1 for these tutorials that includes the class. [url]http://www.runelocus.com/forums/showthread.php?84642-MySQL-with-PHP-Introduction&p=699529#post699529[/url] In part 2 we are going to cover: [LIST] [*]How to include the MySQL Class [*]How to connect to a database [*]Use the select query/function to retrieve data from the database [/LIST] [B][U]Including the class:[/U][/B] For these tutorials the location to our files will be "tutorials/mysql". In that main folder I'm going to have an index.php page and a folder named "includes" which will have the MySQL class (MySQL.php). Open index.php and modify it so it looks like: [PHP]<?php require_once("includes/MysqlDB.php"); ?>[/PHP] Note: You may want to use an IDE such as Netbeans. It will help you a lot. [U][B]Making the Database:[/B][/U] Now that you have your web server installed and running go to [url]http://localhost/phpmyadmin[/url]. You'll either be logged in automatically or use the credentials you used when setting up Wamp to login. Try the user "root" and leave the password empty. Click the button "Databases" up in the top menu and create a new database called tutorial_mysql [B]Username:[/B] root [B]Host:[/B] localhost (leave blank when in "Add user") [B]Database Name:[/B] tutorial_mysql [B]Password:[/B] Also check the box that says "Create database with same name and grant all privileges". This will just create the database and name it the same as the username (tutorial_mysql). Navigate to your tutorial_mysql database (should be in the left hand, side menu), click on "SQL" and execute the following script: [CODE]CREATE TABLE IF NOT EXISTS `users` ( `id` int(4) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `password` varchar(48) NOT NULL, `email` varchar(100) NOT NULL, `age` int(3) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ; -- -- Dumping data for table `users` -- INSERT INTO `users` (`id`, `username`, `password`, `email`, `age`) VALUES (1, 'Surreal', 'password', '[email protected]', 20);[/CODE] This script will create a table named "users" with a structure including a unique ID, username, password, email and age. I've made an example user already and this should already be in your database. [B][U]Initialize the connection/class:[/U][/B] Now we want to open or initialize the MySQL class and construct it. To do this we will add the following line under require_once...... [PHP]$Db = new MySqlDb('localhost', 'root', '', 'tutorial_mysql');[/PHP] Navigate to the page [url]http://localhost/tutorials/mysql/index.php[/url] and you should have a blank page. If it says "There was a problem connecting to the database" then you've done one of the steps wrong and it can't connect to the database we just made. [B][U]The Select Query:[/U][/B] This function can be used to select and export/get data from a database. This can be used to get all details about someone with the username "Surreal" such as their age and password. Here's an example of what it would look like using our MysqlDB Class. [PHP]$Db->where('id', 1); $results = $Db->get('users');[/PHP] You can add this code under the $Db = .... line. Refresh the index.php page and what do we have..? Nothing! Why? These two lines basically mean to look where the id is equal to 1 in the table called users. The $results variable is now an array that has all the data about the user where id = 1. [I][B]How do I show the data?[/B][/I] Under the $results = .... line add the following code: [PHP]?> <pre> <?php print_r($results); ?></pre><?php[/PHP] But what does it mean? The pre tags are html (they keep the array in a state where white space isn't removed. In other words, it looks nicer.) so we keep them out of the PHP hence the reason we close and open the tags. print_r is a PHP function which, for an array will present the values in a format that shows keys and elements. Refresh your index.php page now. Fancy, eh? Your page should look something like this: [CODE] Array ( [0] => Array ( [id] => 1 [username] => Surreal [password] => password [email] => [email protected] [age] => 20 ) ) [/CODE] This is much easier to read now but not very helpful for a functional site, right? Let's display the username, email and age only on the page. We can use a foreach loop to display only the data we want. We only have one result (unique IDs) so it'll only loop once. If we didn't specify the ID or had multiple users with the same ID, it would display the information for each row/user. [PHP]foreach($results as $row): echo "<h2>Username: ".$row['username']."</h2>"; echo "<div>Email: ".$row['email']."</div>"; echo "<div>Age: ".$row['age']."</div>"; endforeach; [/PHP] You can use this code where the previous code was (this one): [PHP]?> <pre> <?php print_r($results); ?></pre><?php[/PHP] Ahh.... much nicer now: [CODE]Username: Surreal Email: [email protected] Age: 20[/CODE] So, that's about all for the select query/function. If you want to fetch all users all you have to do is remove the $Db->where.... line and the foreach loop will just repeat itself for each user. Handy, right? [B][U]For the next step:[/U][/B] You have to do nothing! Next time we'll be looking at the delete and insert functions. [B][U]To sum up:[/U][/B] We can now manually "insert" data via PHPMyAdmin and display it on our site with just a few lines! Pretty cool, right? This script can be used to build a user login system by making a form in HTML and then using the post variables and seeing if the username exists, if yes, check if the password is correct where username = $_POST['username']. Remember to encrypt your passwords! After following the next tutorial you'll be able to add a registration form and have a complete system in place!
  2. You should implement a select all feature for snippets (code bb code). Just a simple click option next to code that highlights all in the selection. [QUOTE] [SIZE=2]Code: [URL="http://runelocus.com/forums/"]Select All[/URL][/SIZE] [SIZE=1]public static void main(String args[]) { System.out.println("Hello world"); }[/SIZE] [/QUOTE] You get the idea. Surprised we don't have this, makes things so much easier :L
  3. I want all my untradables to be kept upon death even if skulled and also for admins to never lose anything on death.
  4. can you do the select all near the code its gone since the forum updated ... ???