[Solved] keep a separate file with php class and pass variable to it [closed]

[ad_1] Put the class in one file, then include it using any of these options: Includes: include ($_SERVER[‘DOCUMENT_ROOT’].’/includes/class.php’); Require: require ($_SERVER[‘DOCUMENT_ROOT’].’/includes/class.php’); Require Once: require_once ($_SERVER[‘DOCUMENT_ROOT’].’/includes/class.php’); Or you can target the class with ajax or a form: /includes/class.php?var=input In the class include you would use: if(!empty($_GET[‘var’])){ //Do some check here for validation //let’s say I’m expecting … Read more

[Solved] Can this be done in PHP? Simple abc “game” [closed]

[ad_1] Yes, this can definitely be done. Look up cookies and the $_GET variable. (This is, assuming you can already code in some other language.) If you can’t code, then this will be a bit harder, but still definitively doable if you’re willing to put down the time to learn. http://www.codecademy.com/ has a course on … Read more

[Solved] How to calculate total of two values in PHP? [closed]

[ad_1] Actually you are doing something really strange, and for you it is better to learn some programming concepts and syntax of PHP language. As I understand your idea the correct code will be <?php $addition = $stats->getLastMonthGirl($userid) + stats->getLastMonthMale($userid); echo “Total:”.$addition.””; ?> [ad_2] solved How to calculate total of two values in PHP? [closed]

[Solved] Parse xml-file and insert into mysql database

[ad_1] The place of mysql_query isn`t correct. You must insert records in loop: foreach ($xml as $syn) { $w1 = $syn->w1; $w2 = $syn->w2; $sql = “INSERT INTO db_name (w1, w2) VALUES (‘$w1′,’$w2’)”; $query = mysql_query($sql); if (!$query) { echo (‘Error: ‘ . mysql_error()); } else { echo “Record added”; } } mysql_close($con); 3 [ad_2] … Read more

[Solved] Redirect to URL with variable inside php

[ad_1] <?php if(isset($_POST[‘action’]) && $_POST[‘action’]!=””) { if(isset($_POST[‘username’]) && $_POST[‘username’]!=””) { header(‘Location: some_other_page.php?username=”.$_POST[“username’]); exit; } } ?> <form action=’index.php’ method=’post’> <input name=”username” type=”text” value=”” placeholder=”Insert username here”> <input type=”submit” value=”Go” name=”Go”> <input type=”hidden” name=”action” value=”do_redirect”> </form> 1 [ad_2] solved Redirect to URL with variable inside php

[Solved] How to range and sequence in PHP

[ad_1] You already mentioned the solution in your question. You can use: range(0, 10) To repeat the sequence 3 times you could do: str_repeat(implode(‘ ‘,range(0, 10)).’ ‘, 3); 1 [ad_2] solved How to range and sequence in PHP

[Solved] PHP custom regroup array [closed]

[ad_1] Simple foreach loop should suffice. Consider this example: $new_values = array(); $values = array( array(‘1393/03’, 5666562, 5), array(‘1393/03’, 491380, 6), array(‘1393/03’, 4210423, 30), array(‘1393/03’, 351000, 55), array(‘1393/03’, 53000, 60), array(‘1393/02’, 15799573, 5), array(‘1393/02’, 1144313, 6), array(‘1393/02’, 12131004, 30), array(‘1393/02’, 39000, 55),); foreach($values as $key => $value) { $new_values[$value[0]][‘Date’] = $value[0]; $new_values[$value[0]][$value[2]] = $value[1]; } … Read more

[Solved] How to read google returned data object in PHP [closed]

[ad_1] If you have an object like this. Follow this example: // THIS IS A SAMPLE, JUST TO SIMULATE how to access values inside class Google_Service_Oauth2_Userinfoplus { public $email=”[email protected]”; public $familyName=”Janorkar”; public $gender = null; public $givenName=”Mona”; public $hd = null; public $id = ‘11018813453254107047543’; public $name=”Mona Janorkar”; public $verifiedEmail = 1; protected $data = … Read more

[Solved] How to echo url and database variable [closed]

[ad_1] You need to use dot to concate constant string with variables: echo ‘<a href=”‘.$url.'”>’.$name.'</a>’; for security reason you need to take care about propper variable escaping. Check php.net doc for htmlspecialchars and htmlentities 1 [ad_2] solved How to echo url and database variable [closed]

[Solved] Javascript ajax don’t work

[ad_1] First callback is not defined and second you also need to call get_lan() function to get it work Updated code function get_lan() { var lan_code = document.getElementById(‘customDropdown1’).value; var params = “lan=” + lan_code; $.ajax({ type: “POST”, url: “api/get_lan.php”, data: params, success: function(result) { document.getElementById(“lan_code”).innerHTML = result; } }); } get_lan(); [ad_2] solved Javascript ajax … Read more

[Solved] Create an array of array values by key [closed]

[ad_1] I could write the code for you, but that feels wrong. Let me point you in the right direction. Start here: http://php.net/manual/en/control-structures.foreach.php You can iterate the array using a key-value foreach and use each array item, which is another array, to access the count and create your new array. Good luck! 1 [ad_2] solved … Read more

[Solved] When I run this PHP code nothing prints to the screen [closed]

[ad_1] There are multiple problems with your latest revision: Problem #1: You should use some variant of mysql_fetch_ in order to fetch the rows from the resource returned by mysql_query(). Using mysql_result can be inefficient. Usually, people use mysql_fetch_assoc(). This will return an array, which you can then access using its key, which depends on … Read more