PHP - New To Load Balancing Database, Which Idea Is Best?
So just to preface this, I have been part of two operations (one as developer, one with a 3rd party company developing) where the business was forced to cease due to difficulties in database load balancing and lots of people lost lots of money. I am talking about big data and high performance needed at the same time.
So for my new project, I am going to try and design it around having a forever expanding infrastructure of servers but that means setting it correctly from the beginning. I have put together some ideas for possible ways to split the database load across multiple servers. Any input to which idea(s) are best would be great so I know which to explore further. Also any relevant info on this type of thing would be helpful as this is the first time I am personally doing this.
Thanks!
Attached Files
db_load_models.jpg 41.98KB
0 downloads
Similar TutorialsHi First of all, I know VERY little about PHP, The effort below is a wile guess that has gone wrong. I get this error Parse error: syntax error, unexpected T_IF in /home/repairyo/public_html/shop/includes/content/viewOrders.inc.php on line 57 I have no idea what ive done wrong, may be I am stupid for attempting it. Cheers Paul This is the original code Code: [Select] $view_orders->assign('VAL_STATE',$lang['glob']['orderState_'.$orders[$i]['status']]); This is the modified code Code: [Select] $view_orders->assign('VAL_STATE',$state = $results[$i]['status'] if ($state == '1') { "<font color='#ff9900'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else if ($state == '2') { "<font color='#009900'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else if ($state == '4') { "<font color='#cc0000'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else if ($state == '5') { "<font color='#cc0000'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else if ($state == '6') { "<font color='#cc0000'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else if ($state == '7') { "<font color='#ff9900'>".$lang['glob']['orderState_'.$results[$i]['status']]."</font>"; } else { $lang['glob']['orderState_'.$orders[$i]['status']]); } This is the code im using: Code: [Select] <?php include "config.php"; if (isset($_GET['id'])) { $id = mysql_real_escape_string($_GET['id']); $sql = "SELECT email FROM gusers WHERE id = $id LIMIT 1"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo "Email: " . $row['email']; } } } I am trying to get more informations than just the e-mail address, but everytime it seems to fail, i am a completly newb to php but ill try my best.... Could someone tell how this is done properly (like loading name, info, and so on from the database and showing it aswell) Hi guys, Should be a simple 1. If i have the following at the top of the page: $page_views = $row['page_views'] + 1; mysql_query("UPDATE table SET page_views='$page_views'"); and then the following at the bottom of the page: echo $row['page_views']; Should I see the page views as 1 the first time the page is visited, 2 the second time the page is visited, and so on......? At the moment im seeing 0 on the first page visit, 1 on the second page visit, 2 on the third..... I had this problem before on another page i was working, and i simply solved it by displaying the mysql query above the echo similar to the code above. However now it does not seem to be working. Am i missing something really simple? lol Thanks hiii all, i want to show the database field (alise name) as the url after index.php when page or site loads first time. how i can achieve it? please help.... thanks in advance This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=349871.0 I'm having a problem and need an answer to why its happening and how to prevent it. Scenario: I begin load my home page which starts with a session_start(); .... Before it FULLY completes loading I try to navigate to another page and BOOM, that page will not load and any other page that begins with session_start(); will not load unless I close and restart the entire browser or wait about 10 minutes.... I will note my website makes ajax calls every 5 seconds or so, but I use setTimeout for them. Any help??? Thanks ahead! HI, I'm writing a auction website .in auction website we need to check for new information every second so it needs to be ajax. we have a timer which calculate the end time of every auction and it needs to be updated every second.Do you have any idea for reducing the process of calculating maybe a client side but something that is updated by server? I mean , the timer works with client side and when the users BID , the timer needs to be refresh.So every time that Bid button hilted the time should be refresh. What's you idea?How can do something like that? Thanks So if I wanted to make sure my users were logged in, and had cookies & JavaScript enabled would this work...? Users enter site at index.php which sets a test cookie and calls itself (header location self in other words) if the test passed the user is redirected to the main page, if not then redirected to a page that has a we need cookies enabled page. Once in the main pages the cookie is checked and if present all good if not send back to index. Then I use session variables to track user data. I see this in my head but I'm not sure it works like I think and I am not sure how to code it. Your feedback would be greatly appreciated, and any pointers in how to code it would be prized as it would help me learn more so I don't have to ask next time. I have a dropdown list where the values are retrieved form the mysql the dropdownlist is coded in php as below: $data = mysql_query("Select * From Project"); echo "<select name = 'Project' onchange = 'showUser(this.value)'>n"; while ($row = mysql_fetch_assoc($data)) { $id = $row['Project_Id']; $ProjectName = $row['ProjectName']; echo "<option value = $id>$ProjectName"; } echo"</select>"; echo "<br/>"; echo "<br/><div id='txtHint' style='width:30em; margin:0 auto;'></div><br/>"; this dropdownlist will retrieved the names of PROJECTS available in the database. when the user click any of the rpojects, it will displayed the engagements that belong to the selected PROJECT. This is also retrieved and display in a dynamic table using ajax. i have created a javascript function as below: <script type="text/javascript"> function showUser(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","try.php?q="+str,true); xmlhttp.send(); } </script> function showUser is placed in the "<select name = 'Project' onchange = 'showUser(this.value)'> my question is, is it possible that i display the data retrieved in the tables as hyperlinks? I want the user to be able to view the informations of the displayed engagements in another php page. the user can view the informations when they clicked on the hyperlinks of the engagement name that is displayed. the sample of table can be seen in the attachment. any idea on how to do this. Let me know cause im stuck I'm building a game and I'm wanting to create mobile monsters for people to click on and fight. I have an arena that works fine, but I would love to have this additional feature. Here's what it would entail: Clicking on the name of the monster. Starting the fight (which is already designed and implemented) I need help with: Is there a way to make a mobile link, essentially. The monsters themselves are identified in a mySQL database with a specific ID. In the arena, the players click on a monster, and the battle begins. So, I need a way to make this "link" mobile. Thoughts? Ideas? Suggestions? Thanks!
Hi guys, thanks OMFG! I have no idea what is going on! Code: [Select] <?php if (isset($user_log)) { //************************************************************************************************************************************************ $user = $_SESSION['user']; $query = " SELECT title, sum, story_id FROM draft WHERE user='$user' "; $select = mysql_query($query); while($rows = mysql_fetch_assoc($select)); { $titledb = $rows['title']; $sumdb = $rows['sum']; $id_db = $rows['story_id']; echo "$titledb"; } } //************************************************************************************************************************************************* ?> I have no idea whats going on I have tried: 1. Using mysql_num_rows I get a number (1) 2.Trying to use the mysql_fetch_assoc outside of the while loop. The values are getting echo'ed out, but when I put the code in the while loop and the Code: [Select] $rows=mysql_fetch_assoc in the while peramiters, nothing happening. I have also tried putting other code in the while loop and it works. Its just the mysql values. also I tried using or die(mysql_errror()), It dies but no mysql error This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=313729.0 A few friends of mine run a little competition between ourselves for a bit of fun. This has been in the past, a sports prediction spreadsheet where we predict the outcomes of champions in various football leagues around the world.
Up to now its always been a very laborious spreadsheet with that my friend can no longer be bothered to do.
is there any way I can do this in php / html?
There would be 8 players predicting the outcome of 6 leagues. We award points for who gets the most, half points for coming close etc.
Any ideas as to what way to approach this would be appreciated. I amvery proficient in HTML and CSS, but a bit of a novice in PHP......but if there is a script or some idea to get this up and running I would be very appreciative.
Thanks
Hi I know my title doesn't give any information but I really have no idea what my problem is. The problem I have is that for some reason my code just stopped working, it was working fine in the beginning and then all of a sudden I'm getting undifined index: item, and I'm not sure what it was that I did wrong since it was working fine in the beginning. Can someone please help because this has me confused Thank you Hi all, i want to write seating plan page, i want it to work by having the logged in user click on a link or image and the system will mark that users username into that seat. I have everything working in terms of the log in but as far as this page goes i really have no idea how i would start with it. If your not sure what i mean i can put it this way to make it much more understandable. If my page had the numbers 1 through to 49 listed down the side and next to each number it says as default "availible", but if the user click on that number the text next to that number changes from "availible" to the users username and no one others can click on that number as its "seat" or "number" has been taken. My users are stored within a mysql database and my site uses sessions like so: $_SESSION[username] = $row[username]; Many thanks for your help i dont know how to fix this problem..please help me guys --- so this is my index Code: [Select] <? session_start(); if(!isset($_SESSION['administrator'])){ header("location:../login.php"); } include ("../config.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title>e-Leave</title> <link rel="stylesheet" href="../style.css" type="text/css" media="all" /> </head> <body> <!-- Header --> <div id="header"> <div class="shell"> <!-- Logo + Top Nav --> <div id="top"> <h1>e-Leave (Cpanel)</h1> <div id="top-navigation"> Welcome <a href="#"><strong><? $user=($_SESSION['administrator']); echo $user; ?></strong></a> <span>|</span> <a href="index.php">Home</a> <span>|</span> <a href="logout.php">Log out</a> </div> </div> <!-- End Logo + Top Nav --> <!-- Main Nav --> <? include ("../header/header_cpanel.php"); ?> <!-- End Main Nav --> </div> </div> <!-- End Header --> <!-- Container --> <div id="container"> <div class="shell"> <!-- Main --> <div id="main"> <div class="cl"> </div> <!-- Content --> <div id="content"> <? if(isset($_GET[view])) { $view = $_GET[view]; } if ($view == '' ){ include ('employeeleaveapplication.php'); } if ($view == 'createaccount' ){ include ('createaccount.php'); } if ($view == 'createaccounta' ){ include ('createaccount_add.php'); } if ($view == 'createaccounti' ){ include ('createaccount_insert.php'); } if ($view == 'createaccountd' ){ include ('createaccount_delete.php'); } if ($view == 'createaccounte' ){ include ('createaccount_edit.php'); } if ($view == 'createaccountu' ){ include ('createaccount_update.php'); } if ($view == 'createlogina' ){ include ('createlogin_add.php'); } if ($view == 'createlogini' ){ include ('createlogin_insert.php'); } if ($view == 'employeedirectory' ){ include ('employeedirectory.php'); } if ($view == 'employeedirectoryl' ){ include ('employeedirectory_list.php'); } if ($view == 'employeedirectorya' ){ include ('employeedirectory_adjustment.php'); } if ($view == 'employeedirectoryai' ){ include ('employeedirectory_adjustment_insert.php'); } if ($view == 'employeedirectoryca' ){ include ('employeedirectory_cancel_adjustment.php'); } if ($view == 'employeedirectorycl' ){ include ('employeedirectory_cancel_application.php'); } if ($view == 'changepassword' ){ include ('changepassword.php'); } if ($view == 'changepasswordi' ){ include ('changepassword_insert.php'); } if ($view == 'branch' ){ include ('setup_branch.php'); } if ($view == 'brancha' ){ include ('setup_branch_add.php'); } if ($view == 'branchi' ){ include ('setup_branch_insert.php'); } if ($view == 'branchd' ){ include ('setup_branch_delete.php'); } if ($view == 'branche' ){ include ('setup_branch_edit.php'); } if ($view == 'branchu' ){ include ('setup_branch_update.php'); } if ($view == 'designation' ){ include ('setup_designation.php'); } if ($view == 'designationa' ){ include ('setup_designation_add.php'); } if ($view == 'designationi' ){ include ('setup_designation_insert.php'); } if ($view == 'designationd' ){ include ('setup_designation_delete.php'); } if ($view == 'designatione' ){ include ('setup_designation_edit.php'); } if ($view == 'designationu' ){ include ('setup_designation_update.php'); } if ($view == 'leavetype' ){ include ('setup_leavetype.php'); } if ($view == 'leavetypea' ){ include ('setup_leavetype_add.php'); } if ($view == 'leavetypei' ){ include ('setup_leavetype_insert.php'); } if ($view == 'leavetyped' ){ include ('setup_leavetype_delete.php'); } if ($view == 'leavetypee' ){ include ('setup_leavetype_edit.php'); } if ($view == 'leavetypeu' ){ include ('setup_leavetype_update.php'); } if ($view == 'publicholiday' ){ include ('setup_publicholiday.php'); } if ($view == 'publicholidayd' ){ include ('setup_publicholiday_delete.php'); } if ($view == 'publicholidaya' ){ include ('setup_publicholiday_add.php'); } if ($view == 'publicholidayi' ){ include ('setup_publicholiday_insert.php'); } if ($view == 'publicholidaye' ){ include ('setup_publicholiday_edit.php'); } if ($view == 'publicholidayu' ){ include ('setup_publicholiday_update.php'); } if ($view == 'report' ){ include ('report.php'); } if ($view == 'report_leave' ){ include ('report_leave.php'); } if ($view == 'print' ){ include ('report_print.php'); } ?> </div> <!-- End Content --> <!-- Sidebar --> <? include ("../header/dashboard_cpanel.php"); ?> <!-- End Sidebar --> <div class="cl"> </div> </div> <!-- Main --> </div> </div> <!-- End Container --> <div id="footer"> <? include ("../footer/footer.php"); ?> </div> </body> </html> -- this is my dashboard panel code Code: [Select] <div id="sidebar"> <!-- Box --> <div class="box"> <!-- Box Head --> <div class="box-head"> <h2><b>Dashboard</b></h2> </div> <!-- End Box Head--> <div class="box-content"> <a href="index.php?view=createaccount"><span> <img src="../images/createaccount.jpg"/> Create Account</span></a> <div class="cl"> </div> <div class="cl"> </div> <a href="index.php?view=employeedirectory"><br><span> <img src="../images/employee.jpg"/> Employee Directory</span></a> <div class="cl"> </div> <a href="index.php?view=report"><br><span> <img src="../images/status-report1.jpg"/> Report</span></a> <div class="cl"> </div> <div class="cl"> </div><a href="index.php?view=changepassword"><br> <span> <img src="../images/key.jpg"/> Change Password</span></a> </div> </div> <div class="box"> <!-- Box Head --> <div class="box-head"> <h2><b>Setup</b></h2> </div> <!-- End Box Head--> <div class="box-content"> <a href="index.php?view=branch"><br><span> <img src="../images/branch.jpg"/> Branch</span></a> <div class="cl"> </div> <div class="cl"> </div><a href="index.php?view=designation"><br> <span> <img src="../images/designation.jpg"/> Designation</span></a> <div class="cl"> </div> <div class="cl"> </div><br> <a href="index.php?view=leavetype"><span> <img src="../images/leave.jpg"/> Leave Type</span></a> <div class="cl"> </div> <div class="cl"> </div><br> <a href="index.php?view=publicholiday"><span> <img src="../images/pb.jpg"/> Public Holiday</span></a> </div> </div> </div> ----- and this is the where the problem page is Code: [Select] <!-- Box --> <div class="box"> <!-- Box Head --> <div class="box-head"> <h2 class="left">Report</h2> </div> <!-- End Box Head --> <!-- Table --> <div class="table"> <div class="right"> <br> </div> <div id="box" valign="top"> <br> <h3><FORM name ="reportbutton" method="post" align="left" action="index.php?view=report"> <strong>Leave Application Listing </strong>| <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Back To Report"> </h3> </FORM> <br><br> <form name="leavebutton" method="post" action="index.php?view=report_leave"> <? $b=$_GET['b']; $m=$_GET['m']; $y=$_GET['y']; if ($b <> '' && $m <> '' && $y <> '') { $branch=$b; $leavemonth=$m; $leaveyear=$y; } else { $branch=$_POST['branch']; $leavemonth=$_POST['leavemonth']; $leaveyear=$_POST['leaveyear']; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query="SELECT * from tblworkgroup"; $result=mysql_query($query);?> Branch <select name="branch" > <option value="all">ALL Branches</option> <? while($row=mysql_fetch_array($result)) { ?> <option value= "<?=$row['WorkGroupID']?>" <? if ($branch==$row['WorkGroupID']){ echo 'selected'; } ?> ><?=$row['WorkGroupName']?></option> <? } ?> </select> </td> </tr> <br><br><br> Month <select name="leavemonth" > <option value = "1" <? if ($leavemonth==1){ echo 'selected'; } ?>>January</option> <option value = "2" <? if ($leavemonth==2){ echo 'selected'; } ?>>February</option> <option value = "3" <? if ($leavemonth==3){ echo 'selected'; } ?>>March</option> <option value = "4" <? if ($leavemonth==4){ echo 'selected'; } ?>>April</option> <option value = "5" <? if ($leavemonth==5){ echo 'selected'; } ?>>May</option> <option value = "6" <? if ($leavemonth==6){ echo 'selected'; } ?>>June</option> <option value = "7" <? if ($leavemonth==7){ echo 'selected'; } ?>>July</option> <option value = "8" <? if ($leavemonth==8){ echo 'selected'; } ?>>August</option> <option value = "9" <? if ($leavemonth==9){ echo 'selected'; } ?>>September</option> <option value = "10" <? if ($leavemonth==10){ echo 'selected'; } ?>>October</option> <option value = "11" <? if ($leavemonth==11){ echo 'selected'; } ?>>November</option> <option value = "12" <? if ($leavemonth==12){ echo 'selected'; } ?>>December</option> </select> Year <select name="leaveyear" > <option value = "2010" <? if ($leaveyear==2010) { echo 'selected';} ?>>2010</option> <option value = "2011" <? if ($leaveyear==2011) { echo 'selected';} ?>>2011</option> <option value = "2012" <? if ($leaveyear==2012) { echo 'selected';} ?>>2012</option> <option value = "2013" <? if ($leaveyear==2013) { echo 'selected';} ?>>2013</option> <option value = "2014" <? if ($leaveyear==2014) { echo 'selected';} ?>>2014</option> <option value = "2015" <? if ($leaveyear==2015) { echo 'selected';} ?>>2015</option> <option value = "2016" <? if ($leaveyear==2016) { echo 'selected';} ?>>2016</option> <option value = "2017" <? if ($leaveyear==2017) { echo 'selected';} ?>>2017</option> </select> <input type='submit' name='submit' value='Preview' Class="button" onclick='return validate()'> </div> </form> <br /><br /> <div id="box" valign="top"> <h3> <strong>Leave Application Details</strong>  </h3> <br><br> <FORM name="printbutton" method="post" align="left" action="report_print.php" target="_blank"> <input type="hidden" name="leavemonth" value="<?php echo $leavemonth; ?>"> <input type="hidden" name="leaveyear" value="<?php echo $leaveyear; ?>"> <input type="hidden" name="branch" value="<?php echo $branch;?>"> <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Print Leave Details"> </form> <table width="80%" align="center" > <thead> <tr> <th width="700px" align="left">Name</a></th> <th width="500px" align="center"></a>Application Date</th> <th width="500px" align="center"></a> </th> <th width="500x" align="right"></a>Reason</th> </tr> </thead> <tbody> <? /*echo "branch:".$branch.'<br />'; echo "leavemonth:".$leavemonth.'<br />'; echo "leaveyear:".$leaveyear.'<br />';*/ //-------------------------------------------------- if ($leavemonth =='' || $leaveyear =='' || $branch == '') { // one value missing, so don't display } else { // start display data $branchtracker = ''; if ($branch=='all'){ $branch = '%'; } $rs = mysql_query( " call vwleavereport('$leavemonth', '$leaveyear', $branch, 0);"); $query="SELECT *, MONTH(tblleaveapplication.DateFrom) as DFMonth, MONTH(tblleaveapplication.DateTo) as DTMonth, YEAR(tblleaveapplication.DateFrom) as DFYear FROM `tblleaveapplication` LEFT JOIN `tblemployee` ON tblleaveapplication.employeeid = tblemployee.id WHERE WorkGroupID LIKE '".$branch."' AND ( (MONTH(tblleaveapplication.DateFrom)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") OR (MONTH(tblleaveapplication.DateTo)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") ) ORDER BY WorkGroupID "; $result = mysql_query($query); while($row=mysql_fetch_array($result)) { if ($branchtracker<>$row['WorkGroupID']){ echo '<tr><td colspan=4 style="background-color: #e8e8e8; font-weight: bold;">'.$row['WorkGroupID'].'</td></tr>'; $branchtracker = $row['WorkGroupID']; } echo '<tr>'; echo '<td>'.$row['EmployeeName'].'</td>'; echo '<td>'.$row['DateFrom'].'</td>'; echo '<td>'.$row['DateTo'].'</td>'; echo '<td>'.$row['Purpose'].'</td>'; echo '</tr>'; } } ?> </table> The problem is the panel should be out on the RIGHT side..how do i fix it. I was wondering if this is faster or better performance. Each time a user submit's a post on my forum I will make it +1 the .txt file on my main server directory called test.txt, then I can just call that on my main forum index to show the amount of total posts our board has, instead of using mysql queries to sum all of it from the tables... good idea? or am i retarded? Hi guys, I have a little issue, I have already got a quiz, here is some of the code from the quiz. Code: [Select] <?php session_start(); session_name("Question_Test"); require_once('questionsandanswers.php'); require_once('functions.php'); if (!isset($_SESSION['questions'])) $_SESSION['questions'] = array(); $id = which_question($_POST['some_field']); $score = 0; if (!isset($_POST['submit'])) { $_SESSION['dclty'] = $_POST['dclty']; if ($_SESSION['dclty'] == "beg") { ?> <script> window.open("extrahelp.php", height=300,width=300); </script> <?php } if ($_SESSION['dclty'] == "int") { ?> <script> window.open("pointers.php", height=300,width=300); </script> <?php } } if (!isset($_POST['submit'])) { $_SESSION['correct'] = array(); $_SESSION['wrong'] = array(); $_SESSION['finished'] = 'no'; if (isset($_SESSION['error'])) { unset($_SESSION['error']); $_SESSION['$num'] = 0; } else { $_SESSION['score'] = $score; $_SESSION['correct'] = array(); $_SESSION['wrong'] = array(); $_SESSION['finished'] = 'no'; $_SESSION['$num'] = 0; } } else { $_SESSION['$num'] = (int) $_POST['num']; $postedanswers = str_replace("_"," ",$_POST['answers']); if ($postedanswers == $answers[$_SESSION['$num']]['0']) { $_SESSION['score'] ++; $_SESSION['correct'][] = $postedanswers; } else { $_SESSION['wrong'][] = $postedanswers; } if ($_SESSION['$num'] < count($questions)-1) { $_SESSION['$num']++; } else { $last = true; $_SESSION['finished'] = 'yes'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <title>Forensics E-learning Package</title> <?php echo $_SESSION['score']; if (!isset($last)) { echo "<script type=\"text/javascript\" src=\"form.js\"></script>"; } ?> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <div id="wrapper"> <div id="header"> <div id="toplinks"> </div> </div> <div id="menu"> <ul> <li><a class="selected" href="home.html">Home</a></li> <li><a href="initialquiz.php">Initial Quiz</a></li> <li><a href="about.php">About</a></li> </ul> </div> <div id="content"> <div id="main"> <h1>Initial Quiz</h1><BR /><BR /> <h1>Protection Section</h1><BR /><BR /> <?php if (!isset($last)){?> <h2>Questions <?php echo $_SESSION['$num']+1; ?>:</h2> <p><strong><?php echo $questions[$_SESSION['$num']]; ?></strong></p> <form id="questionBox" method="post" action="initialquiz.php"> <?php $pattern = ' '; $replace = '_'; $shuffledAnswers = shuffle_assoc($answers[$_SESSION['$num']]); #var_dump($newanswers); foreach ($shuffledAnswers as $answer) { $answer2 = str_replace($pattern,$replace,$answer); echo "<li><input type=\"radio\" id=\"$answer2\" value=\"$answer2\" name=\"answers\" />\n"; echo "<label for=\"$answer2\">$answer</label></li>\n"; } ?> <input type="hidden" name="num" value="<?php echo $_SESSION['$num']; ?>" /> <input type="submit" id="submit" name="submit" value="Submit Answer" /></p> </form><BR /><BR /><b> <?php } else { echo "<p id=\"compare\"><a href=\"detection.php\">Next Section! <img src=\"images/arrow.png\" /></a></p>"; } ?> <?php $_SESSION['$ProtectionPercent'] = number_format(($_SESSION['score'] * 100) / 5); ?> </b> </div> <div id="right"> <h2>Right Menu</h2> <div class="rightitem"> <ul> <li><a class="selected" href="home.html">Home</a></li> <li><a href="initialquiz.php">Initial Quiz</a></li> <li><a href="about.php">About</a></li> </ul> </div> </div> </div> <div class="clearbottom"></div> <div id="footer"> <p id="legal"> </p> </div> </div> </div> </body> </html> The problem is, is that everytime i refresh my page the score counter increments. I have been chatting to a friend and they recommended some coding ideas that may work to stop this, however can any1 help me with a little more on implementing it to my systems? here is the recommended code Code: [Select] session_start(); if (!isset($_SESSION['questions'])) $_SESSION['questions'] = array(); # assuming which_question gives the proper id for the question $id = which_question($_POST['some_field']); # Only handle post data if questions hasn't allready been answered if (!isset($_SESSION['questions'][$id])) { # remove anything other than a-z, A-Z and regular whitespace from answer $answer = preg_replace('#[^a-zA-Z ]#', '', $_POST['answer']); $_SESSION['questions'][$id]['answer'] = $answer; $_SESSION['questions'][$id]['points'] = grade_answer($answer); # ... } Any help would be hugely Appreciated. Thanks Labce PHP newb here - apologies if the answer to this is really simple.
I've tried to add a geotargetting code into my website but it appears the elseif part isn't working, no matter what I do.
Here's the code - any idea why if is fine, and else is fine, but elseif isn't?
<?php if (function_exists('showCountryContentInPage')) { if(showCountryContentInPage(array("us", "ca"),1)) { // US $region = 'USA'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } elseif(showCountryContentInPage(array("at", "es", "cy", "fi", "ee", "fr", "de", "el", "ie", "it", "mt", "lu", "lv", "nl", "pt", "sk", "si", "be"),1)) { // Europe $region = 'Europe'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } else { // UK $region = 'UK'; $country = codediesel_get_users_country(); $store_url = 'URL here'; } ?> |