Jump to content

TechThat

New Members
  • Posts

    3
  • Joined

  • Last visited

Everything posted by TechThat

  1. Thanks. Learned something new today as well. Guess that's the good thing about being new to something
  2. So, I've wrote this code that seems very heavy and unnecessarily long. The code works fine, I was just wondering if there was a better way to write it. It doesn't seems to be very kind to performance(?). The code does a number of thing, I'll try to explain in order: First of, check if $_GET is set: if ((isset($_GET['matchid']))) { Then I need to check 12 $_SESSION variables if they are set, and if not giving a control variable the value of 0. if((isset($_SESSION['match1']))) { $checkmatch1 = $_SESSION['match1']; } else { $checkmatch1 = 0; } if((isset($_SESSION['match2']))) { $checkmatch2 = $_SESSION['match2']; } else { $checkmatch2 = 0; } if((isset($_SESSION['match3']))) { $checkmatch3 = $_SESSION['match3']; } else { $checkmatch3 = 0; } if((isset($_SESSION['match4']))) { $checkmatch4 = $_SESSION['match4']; } else { $checkmatch4 = 0; } if((isset($_SESSION['match5']))) { $checkmatch5 = $_SESSION['match5']; } else { $checkmatch5 = 0; } if((isset($_SESSION['match6']))) { $checkmatch6 = $_SESSION['match6']; } else { $checkmatch6 = 0; } if((isset($_SESSION['match7']))) { $checkmatch7 = $_SESSION['match7']; } else { $checkmatch7 = 0; } if((isset($_SESSION['match8']))) { $checkmatch8 = $_SESSION['match8']; } else { $checkmatch8 = 0; } if((isset($_SESSION['match9']))) { $checkmatch9 = $_SESSION['match9']; } else { $checkmatch9 = 0; } if((isset($_SESSION['match10']))) { $checkmatch10 = $_SESSION['match10']; } else { $checkmatch10 = 10; } if((isset($_SESSION['match11']))) { $checkmatch11 = $_SESSION['match11']; } else { $checkmatch11 = 0; } if((isset($_SESSION['match12']))) { $checkmatch12 = $_SESSION['match12']; } else { $checkmatch12 = 0; } Then I am checking if any of the $_SESSION variables already have the $_GET value: switch($_GET['matchid']) { case $checkmatch1: case $checkmatch2: case $checkmatch3: case $checkmatch4: case $checkmatch5: case $checkmatch6: case $checkmatch7: case $checkmatch8: case $checkmatch9: case $checkmatch10: case $checkmatch11: case $checkmatch12: $errormsg = 'You cannot select the same match twice!'; break; And if not, assigning the $_GET value to the first un-set $_SESSION variable: default: if ((!isset($_SESSION['match1']))) { $_SESSION['match1'] = $_GET['matchid']; } else if ((!isset($_SESSION['match2']))) { $_SESSION['match2'] = $_GET['matchid']; } else if ((!isset($_SESSION['match3']))) { $_SESSION['match3'] = $_GET['matchid']; } else if ((!isset($_SESSION['match4']))) { $_SESSION['match4'] = $_GET['matchid']; } else if ((!isset($_SESSION['match5']))) { $_SESSION['match5'] = $_GET['matchid']; } else if ((!isset($_SESSION['match6']))) { $_SESSION['match6'] = $_GET['matchid']; } else if ((!isset($_SESSION['match7']))) { $_SESSION['match7'] = $_GET['matchid']; } else if ((!isset($_SESSION['match8']))) { $_SESSION['match8'] = $_GET['matchid']; } else if ((!isset($_SESSION['match9']))) { $_SESSION['match9'] = $_GET['matchid']; } else if ((!isset($_SESSION['match10']))) { $_SESSION['match10'] = $_GET['matchid']; $_SESSION['bet10'] = $_GET['bet']; } else if ((!isset($_SESSION['match11']))) { $_SESSION['match11'] = $_GET['matchid']; } else if ((!isset($_SESSION['match12']))) { $_SESSION['match12'] = $_GET['matchid']; } else { $errormsg = 'You cannot select more matches'; } } } Like I said, the code works fine, I would just like to know if there are some better methods to writing any of the code. I'm still learning PHP, and would like to "improve my skills"
  3. Hello freaks! I need to be honest, I registered here for help.. But I've been browsing the forums for about an hour now, and I decided that I need to become a part of this community Im a man in the late 20's from Norway. I have a son who's turning 1 year this July. PHP is not really needed in my work, so it's more of an hobby. I started learning some coding at school, but mostly Im self-learned. I guess I havent coded enough to be called an advanced coder, but I hope to be past the newbie level Currently I have 2 projects going on, 1 at work for internal use, and a web-site I am developing together with a friend. It's not going very fast, as Im trying to spend as much time with my son as possible Im certainly going to stick around, as I see great learning potential here! See you around
  4. Hello freaks! Im new to this forum, but im not all that new to PHP and MySQL. Although there's been some years since the last time I used it, so don't go all freaky on me if I dont do this right Let's go on-topic: Im in progress of making an internal web-page for me and my colleagues to make things a bit easier for us. I am making an database of our different projects, and I need some help with the input form - as I need to upload an image to the server, and store the path in the MySQL database. In my input form, I need to store information from text fields, and I need to upload an image to the server and store the path in the database. Before I can even start to code this (although I have coded the input forum without the upload), I need to know what would be the best way to do this. I guess there are several ways.. What would the expert do (That's you right?)? Should I have the information input, and image upload in the same form, or should I make a second form (maybe on a different page) for the upload? Is it necessary with two tables, one for the info and one for the image path, and then tie them together with the imageID, or is it fine to use just one table? Any thoughts would be appreciated! <!-- TechThat -->
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.