Cronic Posted April 28, 2012 Share Posted April 28, 2012 (edited) Hi there, I'm working on a new function so users can decide between a few game layouts. <?php if ($user_class->bluelayout == 1 ) { ?> <link rel="stylesheet" href="styles/blue.css" type="text/css"> <? } ?> <?php if ($user_class->redlayout == 1){ ?> <link rel="stylesheet" href="styles/red.css" type="text/css"> <? } ?> Im still working on the function that when they change their layout id, it automatically updates in the database too. Just wondering, would this make any sense? Edited April 29, 2012 by Cronic Edit1 Quote Link to comment Share on other sites More sharing options...
sniko Posted April 28, 2012 Share Posted April 28, 2012 Why not something like this, and I've no knowledge with gRPG, but... (Insert database field - `layout`, TINYINT) <?php $layout = array(1 => "blue.css", 2 => "red.css"); // Store css names in an array $layout = $layout[$user_class->layout]; // Search the array for the css file name ?> <link rel="stylesheet" href="styles/<?php echo $layout; ?>" type="text/css" /> I hope that makes sense. Oh, and I assumed the $user_class was fetch object, and the bluelayout/redlayout where the column names.... Quote Link to comment Share on other sites More sharing options...
grant Posted April 28, 2012 Share Posted April 28, 2012 and where you getting this idea from as i just posting in show off mutti game layouts if you want my code will sell you it for $3 comes with 5 lines of code :D Quote Link to comment Share on other sites More sharing options...
rulerofzu Posted April 28, 2012 Share Posted April 28, 2012 This has been done many times before Grant. LOL Searching will find it. Quote Link to comment Share on other sites More sharing options...
grant Posted April 28, 2012 Share Posted April 28, 2012 This has been done many times before Grant. LOL Searching will find it. it sure has Quote Link to comment Share on other sites More sharing options...
Lithium Posted April 28, 2012 Share Posted April 28, 2012 (edited) hmmm... first... add layout to user... ALTER TABLE `grpgusers` ADD `layout` VARCHAR( 30 ) NOT NULL DEFAULT 'default.css' on classes.php add $this->layout = $worked['layout']; To display the css <link rel="stylesheet" href="styles/<?php echo $user_class->layout; ?>" type="text/css" /> Now on user preferences, get a combobox to display all your color schemes, allowing the user to choose... Something along these lines... <form method="post"> <select name="layout" id="layout"> <option value="blue.css">Blue Layout</option> <option value="red.css">Red Layout</option> <option value="green.css">Green Layout</option> <option value="pink.css">Pink Layout</option> </select> <input type="submit" value="Change" /> </form> Obviously you will need to add a few extra lines, but i think you can manage to handle the $_POST Easier than this... impossible! :) Edited April 28, 2012 by Lithium actually... bored!!!! Quote Link to comment Share on other sites More sharing options...
Guest Posted April 28, 2012 Share Posted April 28, 2012 Optionally you could go with javascript and dynamically change your layouts ;). Quote Link to comment Share on other sites More sharing options...
Cronic Posted April 29, 2012 Author Share Posted April 29, 2012 Thanks. works now.. :) I've created it like this: header.php <link rel="stylesheet" href="styles/<?php echo $user_class->layout; ?>" type="text/css" /> header.php if(isset($_POST['submit'])){ $theme = $_POST['layout']; $result = mysql_query("UPDATE `grpgusers` SET `layout` = '".$_POST['layout']."' WHERE `id` = '".$user_class->id."'"); echo Message("You have successfully changed your theme."); <div class="menu"> <h3> Change Site Theme</h3> <div class="bg"> <br> <center> <form method="post"> <select name="layout" id="layout"> <option value="main.css">Default Theme</option> <option value="blue.css">Blue Theme</option> <option value="red.css">Red Theme</option> <option value="green.css">Green Theme</option> </select> <input type='submit' name='submit' value='Change Theme'> </form> </div> </div> Quote Link to comment Share on other sites More sharing options...
Lithium Posted April 29, 2012 Share Posted April 29, 2012 Thanks. works now.. :) I've created it like this: See you used my approach to do it! :) One call for attention... if(isset($_POST['submit'])){ $theme = $_POST['layout']; $result = mysql_query("UPDATE `grpgusers` SET `layout` = '".$_POST['layout']."' WHERE `id` = '".$user_class->id."'"); Post can be manipulated, and you make no sanitize.... that can lead to issues! ;) Quote Link to comment Share on other sites More sharing options...
sniko Posted April 29, 2012 Share Posted April 29, 2012 (edited) Might want to add some insurance on that.... $colours = array("main","blue","red","green"); if( isset($_POST) ) { if( !in_array($_POST['layout'], $colours) ) { $_POST['layout'] = 'main'; } $_POST['layout'] = $_POST['layout'].'css'; // [..] show msg, update field. } else { // [...] foreach($colours as $c) { echo '<option value="', $c ,'.css">', $c ,' theme</option>'; } This is so they can't save the webpage to their computer and change the source code, and execute it. For instance, change this line; <option value="blue.css">Blue Theme</option> To this; <option value="redUltraCoolMagic.css">Red Ultra Cool Magic</option> And then run it on their machine, thus making them not having a theme.... Just some insurance ;) Edit Also, as we all know, the stylesheets will end with .css, so why store '.css'? Say you have 1,000 users, that is (Math, please serve me correctly) .css - 4 bytes 4 bytes * 1000 = 3.90625 kilobytes But say you have 10,000 members, that is (Again, math, please serve me correctly) 4 byes * 10,000 = 39.0625 kilobytes That will be, x amount of memory, wasted. Just something to think about. (I know in the examples given, it's low, but consider if you're on a tight budget, as these 'mistakes', throughout your whole game, was wasting xMB, which not only uses more bandwidth, no matter if you've optimized your queries or not, but server storage space.... Yes. I may be being anal, but think about the top companies, for instance Google. 4 bytes * 1,000,000,000 = 3.7252903 gigabytes Get where I'm going....? Edited April 29, 2012 by sniko being anal. Quote Link to comment Share on other sites More sharing options...
Lithium Posted April 29, 2012 Share Posted April 29, 2012 @sniko, you're being kind :P The problem without sanitizing, something along the lines sniko suggested, may lead to more serious problems than the one sniko showed! :) Quote Link to comment Share on other sites More sharing options...
sniko Posted April 29, 2012 Share Posted April 29, 2012 @sniko, you're being kind :P The problem without sanitizing, something along the lines sniko suggested, may lead to more serious problems than the one sniko showed! :) Oooo thank you! :) I wanted the OP, and other readers, be aware of such things ;) (I also posted about memory wastage) Quote Link to comment Share on other sites More sharing options...
Guest Posted April 29, 2012 Share Posted April 29, 2012 Might want to add some insurance on that.... $colours = array("main","blue","red","green"); if( isset($_POST) ) { if( !in_array($_POST['layout'], $colours) ) { $_POST['layout'] = 'main'; } $_POST['layout'] = $_POST['layout'].'css'; // [..] show msg, update field. } else { // [...] foreach($colours as $c) { echo '<option value="', $c ,'.css">', $c ,' theme</option>'; } This is so they can't save the webpage to their computer and change the source code, and execute it. For instance, change this line; <option value="blue.css">Blue Theme</option> To this; <option value="redUltraCoolMagic.css">Red Ultra Cool Magic</option> And then run it on their machine, thus making them not having a theme.... Just some insurance ;) Edit Also, as we all know, the stylesheets will end with .css, so why store '.css'? Say you have 1,000 users, that is (Math, please serve me correctly) .css - 4 bytes 4 bytes * 1000 = 3.90625 kilobytes But say you have 10,000 members, that is (Again, math, please serve me correctly) 4 byes * 10,000 = 39.0625 kilobytes That will be, x amount of memory, wasted. Just something to think about. (I know in the examples given, it's low, but consider if you're on a tight budget, as these 'mistakes', throughout your whole game, was wasting xMB, which not only uses more bandwidth, no matter if you've optimized your queries or not, but server storage space.... Yes. I may be being anal, but think about the top companies, for instance Google. 4 bytes * 1,000,000,000 = 3.7252903 gigabytes Get where I'm going....? But for arguments sake if you were google 4GB is nothing. Quote Link to comment Share on other sites More sharing options...
sniko Posted May 1, 2012 Share Posted May 1, 2012 But for arguments sake if you were google 4GB is nothing. True, but it will surely be in some sort of procurement policy, I.E not wasting their services (memory wastage) :? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.