[Solved] Sum up array values [closed]

Because $product refers to each iteration of $output[“PriceInformation”][“PriceDetails”][“Price”], you can’t sum the entire array like this. The best way to do it would be to add it to a variable as you go: $your_sum = 0; foreach($output as $value) { $your_sum += $value[‘PriceInformation’][‘PriceDetails’][‘Price’]; } echo ‘Sum: ‘ . $your_sum; 1 solved Sum up array values … Read more

[Solved] mysql_fetch_assoc(): 6 is not a valid MySQL result resource [duplicate]

Make sure to add checks when making your connection as well as after the query $server=”127.0.0.1″; $username=”root”; $password = ”; $database=”test”; mysql_connect($server, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $TableName = “opportunities”; $Opportunities = array(); $SQLString = “SELECT opportunity_ID, company, city, ” . “start_date, end_date, position, description” . ” FROM $TableName;”; $QueryResult = mysql_query($SQLString); if(mysql_error()) … Read more

[Solved] PHP sort array by date and character

Here’s an example multi-sort using usort and a callback: <?php $arr = [ [‘date’ => ‘2017-10-18’, ‘char’ => ‘Z’], [‘date’ => ‘2017-10-17’, ‘char’ => ‘Z’], [‘date’ => ‘2017-9-2’, ‘char’ => ‘A’], [‘date’ => ‘2017-10-17’, ‘char’ => ‘A’], [‘date’ => ‘2017-10-18’, ‘char’ => ‘A’], ]; usort($arr, function($a, $b) { $date_a = strtotime($a[‘date’]); $date_b = strtotime($b[‘date’]); if($date_a … Read more

[Solved] SQL trouble with dots in data [closed]

Could you use a regular expression to match the URL? You didn’t include the query… /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/ The above would be a regular expression to match a URL including the https and double forward slash Numbers, letters, dots, and hyphens are included here. And in MySQL you could use this to match it: http://dev.mysql.com/doc/refman/5.1/en/regexp.html#operator_regexp solved … Read more

[Solved] Regular expression php for a pro [closed]

Here is my version: function test($v) { if (preg_match(‘/^\\[(“number”)(,”number”)*\\]$/’, $v)) echo ‘ok<br>’; else echo ‘fail<br>’; } or if “number” is really digits, this one: function test($v) { if (preg_match(‘/^\\[(“[0-9]+”)(,”[0-9]+”)*\\]$/’, $v)) echo ‘ok<br>’; else echo ‘fail<br>’; } NOTE – only positive naturals are accepted, need to change to negative and decimal/floating numbers 1 solved Regular expression … Read more

[Solved] Login PHP it’s not working [closed]

You have many errors in your code : $result = mysql_query(“SELECT * FROM utilizatori WHERE username=”” . $loginUsername . “” and parola=””. $loginUsername.”””); You check username and parola on same var. You probably want : $result = mysql_query(“SELECT * FROM utilizatori WHERE username=”” . $loginUsername . “” and parola=””. $loginPassword.”””); You are also affecting vars … Read more

[Solved] php not converting dates

This is because date_format accepts an object and not a string. You should use the function date and pass to it’s second argument a timestamp. solved php not converting dates

[Solved] Displaying an error message in PHP [closed]

If you are using mysql to search the database for matches, then use something like below $email = $mysqli->escape_string($_POST[’email’]); $password = $mysqli->escape_string($_POST[‘password’]): $result = $mysqli->query(“SELECT * FROM users WHERE email=”$email” AND password=’$password'”); //check whether the user exists and redirecting if not exists if ($result-> num_rows == 0){ $_SESSION[‘messege’]= “You have entered Either Wrong Username or … Read more

[Solved] PHP: Echoing XML code- variable in the tag

Define a variable and use it in the echo like: echo ‘<Say voice= “‘.$voice.'” language=”fr”>stuff</Say>’; Give $voice whatever value you want. Also, escape the inner quotes if you need any! echo ‘<Say voice= “‘.$gender.'” language=”fr”>\’\'</Say>’; solved PHP: Echoing XML code- variable in the tag

[Solved] I want to pass a unique variable ie product code or product id from database in url of a product [closed]

You can use Get Variables like: sitename.com/index.php?id=1234 And in the index.php something like: <?php $DBuser = “XXX”; $DBpassword = “XXX”; $DBhost = “localhost”; $DBname = “XXX”; $mysqli = new mysqli($DBhost, $DBuser, $DBpassword, $DBname); if ($mysqli->connect_errno) { printf(“Connect failed: %s\n”, $mysqli->connect_error); exit(); } if ($result=$mysqli->multi_query(“SELECT * FROM productos WHERE id='”.$_GET[‘id’].”‘ LIMIT 1″)) { $data = mysqli_fetch_assoc($result) … Read more