I have to create a html table for a room booking system, but i have hit a wall trying to think of ways to insert data into cells. At the moment i am getting data from a database (start time and end time for the booking). I then loop through the times from an array and use an if statement to compare the start time to the time in the time array.
This is what i have at the moment :
Room booking image
The main problem that i am having is that in my database if there are two bookings on the same day it will only show that last one in the array.
$tableStart = "<table class='table_main'><thead><tr id='table_first' class='first_last'><th class='first_last'>Time:</th>";
$tableMid = "</tr></thead><tbody>";
$tableEnd = "</tbody></table>";
foreach ($newBookings as $booking) {
$tableStart .= "<th class='first_last'>$booking[0]</th>";
}
foreach ($times as $time) {
$tableMid .= "<tr class='even_row'><td class='time'>{$time['times']}</td>";
$i = 0;
foreach ($newBookings as $booking) {
unset($booking[0]);
$x = count($booking);
if ($x > 0) {
if ($booking[$i]['start_Time'] == $time['times']) {
$tableMid .= "<td class='new'>{$booking[$i]['start_Time']}</td>";
} else if($booking[$i]['end_Time'] == $time['times']) {
$tableMid .= "<td class='new'>{$booking[$i]['end_Time']}</td>";
} else {
$tableMid .= "<td class='new'></td>";
}
} else {
$tableMid .= "<td class='new'></td>";
}
++$i;
}
}
$tableStart .= $tableMid;
$tableStart .= $tableEnd;
return $tableStart;`
The way i have my data set up at the moment in the arrays currently look like this:
$times = [
0 => ['06:00'],
1 => ['06:30'],
2 => ['07:00'],
3 => ['07:30'],
4 => ['08:00'],
5 => ['08:30'],
6 => ['09:00'],
7 => ['09:30'],
8 => ['10:00'],
9 => ['10:30'],
10 => ['11:00'],
11=> ['11:30'],
12 => ['12:00'],
13 => ['12:30'],
14 => ['13:00'],
15 => ['13:30'],
16 => ['14:00'],
17 => ['14:30'],
18 => ['15:00'],
19 => ['15:30'],
20 => ['16:00'],
21 => ['16:30'],
22 => ['17:00'],
23 => ['17:30'],
24 => ['18:00'],];
$newBookings = [
0 => [
0 => 'Room 33'
],
1 => [
0 => 'New room 8',
1 => [
'room_Name' => 'New room 8',
'start_Time' => '11:30',
'end_Time' => '12:30'
]
],
2 => [
0 => 'sds',
1 => [
'room_Name' => 'sds',
'start_Time' => '09:30',
'end_Time' => '11:30'
],
2 => [
'room_Name' => 'sds',
'start_Time' => '14:30',
'end_Time' => '16:30'
]
],
3 => [
0 => 'New Room 3'
],
4 => [
0 => 'NewRoom5'
],
5 => [
0 => 'New room 55'
]
];
I apologise if i have left anything out or am too vague with my description. Thank you
For anyone who sees this i found a fix, i used ADyson's recommendation for the array and reworked my code so that it now works correctly. For anyone interested here is the code i used :
public function render(): string
{
$data = $this->tableData; //from abstract class contains table data
$times = $this->tableTimes; //gets times
$rooms = $this->roomNames; //gets room names
$startTime = $times[0]['start_time']; //sets the start time
$endTime = $times[0]['end_time']; // sets the end time
$times = $this->setTimeArray($startTime, $endTime); //goes to function
$newBookings = $this->setDataArray($data, $rooms); // goes to function
$tableStart = "<table class='table_main'><thead><tr id='table_first' class='first_last'><th class='first_last'>Room:</th>";
$tableMid = "</tr></thead><tbody>";
$tableEnd = "</tbody></table>";
foreach ($times as $key => $time) {
$tableStart .= "<th class='first_last'>{$time}</th>";
}
foreach ($newBookings as $booking) {
$tableMid .= "<tr class='even_row'><td class='room_Name'>{$booking['Room']}</td>";
$x = 0;
$e = 0;
foreach ($times as $time) {
if ($x == count($booking['Bookings'])) {
$x = 0;
}
if ($e == count($booking['Bookings'])) {
$e = 0;
}
if (count($booking['Bookings']) < 1) {
$tableMid .= "<td class='new'></td>";
} else if ($booking['Bookings'][$x]['start_Time'] == $time) {
$tableMid .= "<td class='room_Booked'>{$booking['Bookings'][$x]['start_Time']}</td>";
$x++;
} else if ($booking['Bookings'][$e]['end_Time'] == $time) {
$tableMid .= "<td class='room_Booked'>{$booking['Bookings'][$e]['end_Time']}</td>";
$e++;
} else {
$tableMid .= "<td class='new'></td>";
}
}
}
$tableStart .= $tableMid;
$tableStart .= $tableEnd;
return $tableStart;
}
Setting the times to an array
public function setTimeArray($startTime, $endTime)
{
$i = 0;
$endTimes = strtotime($endTime);
$endTime = date("H:i", strtotime('+30 minutes', $endTimes));
do {
$times[$i] = $startTime;
$time = strtotime($startTime);
$startTime = date("H:i", strtotime('+30 minutes', $time));
$i++;
} while ($startTime != $endTime);
return ($times);
}
Putting room booking data into one array
public function setDataArray($data, $rooms)
{
$newBookings = [];
$x = 0;
foreach ($rooms as $key) {
$newBookings[$x] = array(
'Room' => $key['room_name'], 'Bookings' => []
);
$y = 0;
foreach ($data as $value) {
if ($value['room_name'] == $newBookings[$x]['Room']) {
$newBookings[$x]['Bookings'][$y] = [
'room_Name' => $value['room_name'],
'start_Time' => $value['requested_time'],
'end_Time' => $value['requested_time_end']
];
$y++;
}
}
$x++;
}
return ($newBookings);
}
Related
I have a foreach but it only returns the last value and not all the values, what is the problem?
my array
array:1 [▼
"ciudad" => array:15 [▼
0 => "Piura"
1 => "10"
2 => "0"
3 => "Lima"
4 => "20"
5 => "0"
6 => "Pisco"
7 => "30"
8 => "0"
9 => "Arequipa"
10 => "40"
11 => "0"
12 => "Loreto"
13 => "50"
14 => "0"
]
]
My code:
public function updateciudadpreciosdelivery(Request $request)
{
$data = $request->except(['_token', 'restaurant_id']);
$i = 0;
$result = [];
foreach ($data as $day => $times) {
$day_result = [];
foreach ($times as $key => $time) {
if ($key % 3 == 0) {
$day_result["open"] = $time;
}
elseif ($key % 2 == 0) {
$day_result["cod"] = $time;
}
else {
$day_result["close"] = $time;
}
}
$result[$day][] = $day_result;
}
// Fetches The Restaurant
$restaurant = Restaurant::where('id', $request->restaurant_id)->first();
// Enters The Data
if (empty($result)) {
$restaurant->deliveryciudadprecios = null;
}
else {
$restaurant->deliveryciudadprecios = json_encode($result);
}
$restaurant->delivery_charge_type = 'XCIUDAD';
// Saves the Data to Database
$restaurant->save();
return redirect()->back()->with(['success' => 'Las ciudades se guardaron correctamente']);
}
Currently it only returns the last value
"{"ciudad":[{"open":"Loreto","close":"50","cod":"0"}]}"
I need you to return the following (example)
{"ciudad":[{"open" :"Piura","close" :"10","cod" :"0"},{"open" :"Lima","close" :"20","cod" :"0"},{"open" :"Pisco","close" :"30","cod" :"0"},{"open" :"Arequipa","close" :"40","cod" :"0"},{"open" :"Loreto","close" :"50","cod" :"0"}]}
If it is not clear I will try to improve it
If we consider your data won't change, and you have 3 entries to get, you can use array_chunk:
$result = [];
foreach ($data as $day => $times) {
$timesChunked = array_chunk($times, 3);
foreach ($timesChunked as $time) {
$result[$day] []= [
'open' => $time[0],
'close' => $time[1],
'code' => $time[2],
];
}
}
But your problem was logical, you don't change the key in your loop, of course your array will have only the last elements. Reread your code, and try to understand why.
I created the following Array ($stuArr) in PHP.
I want to print the Array in an HTML-Table so that I can create a Table like this (Calendar-System):
The numbers in the table are the dates of the month.
And each user has a own row. I generate the table with this:
$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$days = $days + 2;
echo "<table border='1'>";
echo "<tr>";
for ($j = 0; $j < $days; $j++) {
echo "<th>$j</th>";
}
echo "</tr>";
//Person
$file = file_get_contents('MOCK_DATA-100.json');
$data = json_decode($file);
//Events
$file2 = file_get_contents('calendar.json');
$data2 = json_decode($file2);
$stuArr = [];
foreach($data as $student) {
$id = $student->id;
$name = $student->name;
$mark = false;
foreach($data2 as $cal) {
if($cal->resource == $id) {
$start = new DateTime(substr($cal->start, 0, 10));
$end = new DateTime(substr($cal->end, 0, 10));
$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($start, $interval, $end);
$dd = [];
if($month == $start->format('n')) {
foreach ($period as $dt) {
if($month != $dt->format('n'))
break;
$dd[] = $dt->format("j");
}
$stuArr[] = [$id, $dd];
}
}
}
}
var_export($stuArr);
foreach($stuArr as $student) {
$id = $student[0];
$dates = $student[1];
}
echo "</table>";
Output of var_export($stuArr);:
array ( 0 => array ( 0 => '2', 1 => array ( 0 => '22', 1 => '23', 2 => '24', 3 => '25', ), ), 1 => array ( 0 => '3', 1 => array ( 0 => '23', 1 => '24', 2 => '25', ), ), )
Thanks for your help! Regards, Fynn
If you have any question for me or need an explanation of some part of the code, just say it!!!
Error:
Try the below code. I can see you printed o-29 as days, try starting from 1 instead of 0 in the loop.
// update inside the Student loop, previous code remains as it is
foreach($stuArr as $student) {
$dates = $student[1];
echo "<tr>";
for ($j = 1; $j <= $days; $j++) {
if(in_array($j, $dates))
echo "<td>X</t>";
else
echo "<td> </td>";
}
echo "</tr>";
}
can you give me idea how to implement this idea for "dynamic" html table.
I have an array
$arr = array(
array(
'label' => 'First name',
'data' => array(
array('fname' => 'John'),
array('fname' => 'Ralph'),
),
),
array(
'label' => 'Last name',
'data' => array(
array('lname' => 'Doe'),
array('lname' => 'Loren'),
),
),
array(
'label' => 'Description',
'data' => array(
array('description' => 'Something bout John'),
array('description' => 'Something about Ralph'),
),
),
);
Now from the keys 'label' im creating the table columns
---------------------------------------
|First Name | Last Name | Description |
---------------------------------------
The problem is how to put 'fname' keys in the first column, 'lname' in the second and 'description' in the third.
With this part of code im trying to put the data in all columns
private function tableBody()
{
$data = $this->data;
$table = '<tbody>';
foreach($data as $key => $value){
foreach($value['data'] as $k => $v){
$table .= '<tr>';
foreach($v as $col => $name){
$table .= '<td>' . $name . '</td>';
}
$table .= '</tr>';
}
}
$table .= '</tbody>';
return $table;
}
Also my idea is not to hard code array keys for multiple usage(except label and data).
First I would remap the data to process it in loops.
$labels = [];
$rows = [];
foreach($arr as $column) {
$label = $column['label'];
$labels[] = $label;
foreach($column['data'] as $key => $value) {
$rows[$label][] = $value;
}
}
Now print out the labels with the headline.
echo "<table>\n";
echo "<tr>";
foreach($labels as $label) echo "<th>{$label}</th>";
echo "</tr>\n";
Iterate through the rows and create the HTML.
$labelCount = count($labels);
$rowCount = count($rows[$labels[0]]);
while($rowCount) {
echo "<tr>";
for ($i = 0; $i < $labelCount; $i++) {
$current = array_shift($rows[$labels[$i]]);
$value = reset($current);
echo "<td>{$value}</td>";
}
echo "</tr>\n";
$rowCount--;
}
echo "</table>\n";
This gives a table like below
<table>
<tr><th>First name</th><th>Last name</th><th>Description</th></tr>
<tr><td>John</td><td>Doe</td><td>Something bout John</td></tr>
<tr><td>Ralph</td><td>Loren</td><td>Something about Ralph</td></tr>
</table>
You need to manipulate the initial array to reduce it to something more manageable. You could brute force your way like so:
function reduce($data) {
$ret = [];
foreach ($data as $d1) {
// column header could have been fetched here
foreach ($d1 as $k2 => $d2) {
// keeping track of what label we need
$key = '';
// keeping the values together
$child = [];
// discarding non arrays
if (is_array($d2)) {
foreach ($d2 as $d3) {
// identifier fetch from this level
foreach ($d3 as $k4 => $d4) {
$key = $k4;
$child[] = $d4;
}
}
}
// assigning back to the main array only if we have something
if (!empty($child)) {
$ret[$key] = $child;
}
}
}
return $ret;
}
That will return the following:
Array
(
[fname] => Array
(
[0] => John
[1] => Ralph
)
[lname] => Array
(
[0] => Doe
[1] => Loren
)
[description] => Array
(
[0] => Something bout John
[1] => Something about Ralph
)
)
In my lottery project I have 5 tickets, in which you select numbers and buy. The thing is, you can only buy the tickets if you buy them in order... For example:
Ticket 1 Ticket 2 Ticket 3 Ticket 4 Ticket 5
If you add numbers to the ticket 1 and then the others it works... If you skip the ticket 1 and add numbers to the other ones, when you try to buy you get this error:
ContextErrorException: Notice: Undefined offset: 0 in C:\wamp\www\Digidis\front\src\MediaparkLt\UserBundle\Service\MoneyManager.php line 313
The full stack:
array('cartProduct' => array('title' => 'EUROMILLONES', 'price' => '2.35', 'product' => '2', 'ticket_id' => '1433921783_19792', 'numbers' => '8,13,14,17,37', 'stars' => '4,7', 'betslip' => '{"duration":"1","subscription":"false","jsPrice":"235","type":"simple","numbers1":"0,0,0,0,0","numbers2":"8,13,14,17,37","numbers3":"0,0,0,0,0","numbers4":"0,0,0,0,0","numbers5":"0,0,0,0,0","stars1":"0,0","stars2":"4,7","stars3":"0,0","stars4":"0,0","stars5":"0,0","dayOfWeek":"3"}', 'is_syndicate' => false, 'draw' => object(DateTime)), 'product' => object(Product), 'user' => object(User), 'reference' => null, 'paymentResult' => 'Authorised', 'bets' => object(stdClass), 'individualBets' => array(), 'tickets' => array(array('numbers' => '8,13,14,17,37', 'stars' => '4,7')), 'k' => '0', 't' => array('numbers' => '0,0,0,0,0', 'stars' => '0,0'), 'is_ticket_filled' => false, 'week_id' => array(array('ticketId' => '7005')), 'g' => '0', 'lastId' => '7005', 'purchase' => object(Purchase), 'price' => '2.35', 'bet' => object(Bet), 'euromillonesBet' => object(EuromillonesBet), 'drawDate' => array(object(DrawDate)), 'j' => '0')) in C:\wamp\www\Digidis\front\src\MediaparkLt\UserBundle\Service\MoneyManager.php line 313
As you can see first it gets the ticket 1, which is empty(or 0) and thats why it causes the error... How can I make it so that it skips the empty tickets?
Here is the controller where the error occurs:
$bets = json_decode($cartProduct['betslip']);
$individualBets = array();
$tickets = array(
array('numbers' => $bets->numbers1, 'stars' => $bets->stars1),
array('numbers' => $bets->numbers2, 'stars' => $bets->stars2),
array('numbers' => $bets->numbers3, 'stars' => $bets->stars3),
array('numbers' => $bets->numbers4, 'stars' => $bets->stars4),
array('numbers' => $bets->numbers5, 'stars' => $bets->stars5)
);
if ($bets->type === 'simple') {
foreach ($tickets as $k => $t) {
$is_ticket_filled = ((int) str_replace(',', '', $t['numbers'])) > 0;
if (!$is_ticket_filled) {
unset($tickets[$k]);
}
}
} else if ($bets->type === 'multiple') {
$tickets = array(array('numbers' => $bets->numbers1, 'stars' => $bets->stars1));
}
$week_id = null;
for ($k = 0; $k < (count($tickets)); $k++) {
for ($g = 0; $g < $bets->duration; $g++) {
if (!isset($week_id[$g])) {
$week_id[$g] = $this->entityManager->getRepository('MediaparkLtLotteryBundle:Bet')->getLastTicketId();
if ($week_id[$g]) {
$week_id[$g]['ticketId'] ++;
} else {
$week_id[$g]['ticketId'] = 0;
}
}
$lastId = $week_id[$g]['ticketId'];
$purchase = new Purchase();
$purchase->setUser($user);
$purchase->setDrawDate($cartProduct['draw']);
$purchase->setProduct($product);
$purchase->setReference($reference);
$price = $cartProduct['price'];
$bet = new Bet();
if ('eurojackpot' == $product->getAlias()) {
$euromillonesBet = new EurojackpotBet();
} else {
$euromillonesBet = new EuromillonesBet();
}
$drawDate = $this->entityManager->getRepository('MediaparkLtLotteryBundle:DrawDate')->findByDrawDate($cartProduct['draw']);
if (!$drawDate)
die('no draw date found ' . $cartProduct['draw']->format('Y-m-d H:i:s'));
$bet->setDrawDate($drawDate[0]);
$bet->setTicketId($lastId);
if (strtoupper($paymentResult) === 'AUTHORISED') {
$bet->setStatus(BetStatus::AUTHORISED);
} else {
$bet->setStatus(BetStatus::FAILED);
}
$bet->setWinnings(0);
$euromillonesBet->setBet($bet);
/// LINE 313 ABOVE!!!!!!!
$numbers = $this->getNumbersArray($tickets[$k]['numbers']);
$j = 0;
foreach ($numbers as $number) {
$j++;
$name = 'setN' . $j;
$euromillonesBet->$name($number);
}
$numbers = $this->getNumbersArray($tickets[$k]['stars']);
$euromillonesBet->setS1($numbers[0]);
$euromillonesBet->setS2($numbers[1]);
$euromillonesBet->setAmountOfStars(Bet::NUMBER_OF_STARS);
$purchase->addBet($bet);
$purchase->setPricePaid($price);
if (strtoupper($paymentResult) === 'AUTHORISED') {
$purchase->setStatus(PaymentStatus::AUTHORISED);
} else {
$purchase->setStatus(PaymentStatus::FAILED);
}
if ($bets->subscription === "true") {
$contract = new PurchaseContract();
$contract->setAccumulatedWinnings(0);
$contract->setCancellationDate(null);
$contract->setFirstDrawDate($purchase->getDrawDate());
$contract->setLastRenewedDate($purchase->getDrawDate());
$contract->setNextRenewalFirstDrawDate($purchase->getDrawDate());
// $contract->setPurchase($purchase);
$contract->setStatusPurchaseContract(1);
$contract->setWeeks(1);
$purchase->setPurchaseContract($contract);
$this->entityManager->persist($contract);
}
if ($g == 0)
$individualBets[] = $euromillonesBet;
$this->entityManager->persist($bet);
$this->entityManager->persist($euromillonesBet);
$this->entityManager->persist($purchase);
$this->entityManager->flush();
}
}
return $individualBets;
}
From what I see the bet type in your object is set to "type":"simple" and numbers1":"0,0,0,0,0"
$is_ticket_filled = ((int) str_replace(',', '', $t['numbers'])) > 0;
//(int) 00000 = 0
if (!$is_ticket_filled) {
unset($tickets[$k]);
}
Is causing the issue since unset does not reset the array indexes.
http://ideone.com/5q74Wv
Then later you iterate using for($k=0; $k < count($tickets); $k++)
You should instead rebase the array after using unset($tickets[$k])
if ($bets->type === 'simple') {
//...
$tickets = array_values($tickets);
}
or check the existence of the ticket when iterating over indexes
$ticketCount = count($tickets);
for ($k=0; $k < $ticketCount; $k++) {
if (false === isset($tickets[$k]) {
continue;
}
//...
}
or easier still, iterate over the existing tickets array using foreach instead of for.
foreach ($tickets as $k => $ticket) {
//...
}
Then change $tickets[$k] with just $ticket since $k is not used anywhere else.
For a rent application, I have an array $dates like this:
Array
(
[2013-07-19] => 1
[2013-07-21] => 3
[2013-07-23] => 2
[2013-07-24] => 4
[2013-07-25] => 4
[2013-07-26] => 2
[2013-07-27] => 2
[2013-07-30] => 3
[2013-07-31] => 1
)
The date is the key, and the values are the number of items rent in that day for a specific product
How can I split this array in many sub arrays containing each a list of consecutive days?
Like this:
Array
(
[0] => Array
(
[2013-07-19] => 1
)
[1] => Array
(
[2013-07-21] => 3
)
[2] => Array
(
[2013-07-23] => 2
[2013-07-24] => 4
[2013-07-25] => 4
[2013-07-26] => 2
[2013-07-27] => 2
)
[3] => Array
(
[2013-07-30] => 3
[2013-07-31] => 1
)
)
$newArray = array();
foreach ($array as $date => $value)
{
// Make sure the newArray starts off with at least one element
if (empty($newArray))
$newArray[] = array();
// Calculate the difference in dates.
// (I like using DateTime, but use whichever method you like)
$dateTime = new DateTime($date);
$lastDateTime = new DateTime($lastDate);
$dateDiff = $dateTime->diff($lastDateTime);
// Add a new array to the end if the difference between this element and the last was more than a day
if ($dateDiff->days > 1)
$newArray[] = array();
// We can now be guaranteed that the last element of $newArray is the one we want to append to
$newArray[count($newArray) - 1][$date] = $value;
// Keep track of the last date you saw
$lastDate = $date;
}
Here it is in action: https://eval.in/38039
$newArray = array();
$i = 0;
foreach ($array as $date => $key) {
$thisDay = end(explode('-', $date));
$nextDay = end(explode('-', next($array[$date])));
if ($thisDay + 1 != $nextDay + 0)
$i++;
if (!isset($newArray[$i])) {
$newArray[$i] = array($date => $key);
} else {
if (!isset($newArray[$i][$date])) {
$newArray[$i][$date] = $key;
} else {
$newArray[$i][$date] = $key;
}//END IF
}//END IF
}//END FOREACH LOOP
This is the code i would use to do what you are asking.
UPDATE:
I was wrong above. i have altered the code to work this time:
$newArray = array();
$i = 0;
foreach ($array as $date => $key) {
$thisDay = end(explode('-', $date));
$nextDay = array_key_exists(date('Y-m-d', strtotime($date . ' +1 day')), $array);
if (!isset($newArray[$i])) {
$newArray[$i] = array($date => $key);
} else {
if (!isset($newArray[$i][$date])) {
$newArray[$i][$date] = $key;
} else {
$newArray[$i][$date] = $key;
}//END IF
}//END IF
if (!$nextDay)
$i++;
}//END FOREACH LOOP
Here is my test case:
<?php
$array = array(
'2013-07-19' => 1,
'2013-07-21' => 3,
'2013-07-23' => 2,
'2013-07-24' => 4,
'2013-07-25' => 4,
'2013-07-26' => 2,
'2013-07-27' => 2,
'2013-07-30' => 3,
'2013-07-31' => 1
);
echo '<pre>' . print_r($array, true) . '</pre>';
$newArray = array();
$i = 0;
foreach ($array as $date => $key) {
$thisDay = end(explode('-', $date));
$nextDay = array_key_exists(date('Y-m-d', strtotime($date . ' +1 day')), $array);
if (!isset($newArray[$i])) {
$newArray[$i] = array($date => $key);
} else {
if (!isset($newArray[$i][$date])) {
$newArray[$i][$date] = $key;
} else {
$newArray[$i][$date] = $key;
}//END IF
}//END IF
if (!$nextDay)
$i++;
}//END FOREACH LOOP
echo '<pre>' . print_r($newArray, true) . '</pre>';
?>
you can do it like this:
$data = array(
'2013-07-19' => 1,
'2013-07-21' => 3,
'2013-07-23' => 2,
'2013-07-24' => 4,
'2013-07-25' => 4,
'2013-07-26' => 2,
'2013-07-27' => 2,
'2013-07-30' => 3,
'2013-07-31' => 1
);
$result = array();
$ref = new DateTime('1821-11-11');
foreach ($data as $datum => $nb) {
if ($ref->add(new DateInterval('P1D'))->format('Y-m-d')!=$datum) {
$result[] = array();
$ref = new DateTime($datum);
}
$result[array_pop(array_keys($result))][$datum] = $nb;
}
print_r($result);