Page 1 of 1

Need help on my database code! :s

Posted: Wed Aug 21, 2013 9:10 am
by tannj001
Hi guys,

Need some help on some code I have been given. :banghead:

Was given this over the summer holidays for a challenge but cant get my head around it! I want the code to show the value of the (added together) integer field $pax_number and then print out the total. I've attached the code below,
PHP Code - Database
PHP Code - Database
If anyone can help please let me know as my heads about to explode!

JeyTee :)

Re: Need help on my database code! :s

Posted: Wed Aug 21, 2013 11:36 am
by litebearer
Might try...

Code: Select all

<?php
$pax = "1-220-456-7890";
$new_pax = preg_replace("/[^0-9]/","",$pax); /* remove all non numeric characters */
echo $new_pax ."<br>";
$my_array = str_split($new_pax); /* create an array of the numeric characters */
$x = count($my_array); /* count the elements in the array */
$i = 0; 
$total = 0;
while($i<$x) {
	$total = $total + $my_array[$i];
	$i ++;
}
echo $total;
?>