我将下一个信息存储在wp表中
a:83:{i:0;s:0:"";s:10:"hotel_name";s:10:"Casa Coral";s:13:"hotel_address";s:39:"Constanta, Mamaia Nord, Str. D2, Nr. 28";s:14:"hotel_locality";s:22:"Constanta, Mamaia Nord";s:15:"hotel_telephone";s:12:"0728.330.713";s:11:"hotel_email";s:19:"office@vilacoral.ro";s:13:"hotel_checkin";a:2:{s:4:"from";s:2:"15";s:2:"to";s:2:"16";}s:14:"hotel_checkout";a:2:{s:4:"from";s:2:"11";s:2:"to";s:2:"12";}s:18:"hotel_pets_message";s:16:"Pets are allowed";s:12:"listing_page";s:2:"12";s:12:"booking_page";s:2:"13";s:20:"reservation_received";s:20:"reservation-received";s:12:"pay_endpoint";s:15:"pay-reservation";s:8:"currency";s:3:"IDR";s:17:"currency_position";s:5:"after";s:19:"thousands_separator";s:1:",";s:17:"decimal_separator";s:1:".";s:14:"room_size_unit";s:3:"m²";s:15:"listing_sorting";s:5:"title";s:18:"low_room_threshold";i:1;s:23:"room_catalog_image_size";a:3:{s:5:"width";i:480;s:6:"height";i:294;s:4:"crop";i:1;}s:22:"room_single_image_size";a:3:{s:5:"width";i:1140;s:6:"height";i:699;s:4:"crop";i:1;}s:25:"room_thumbnail_image_size";a:3:{s:5:"width";i:85;s:6:"height";i:85;s:4:"crop";i:1;}s:13:"room_lightbox";s:1:"1";s:12:"booking_mode";s:14:"manual-booking";s:30:"booking_additional_information";s:1:"1";s:22:"booking_minimum_nights";i:1;s:20:"booking_hold_minutes";i:120;s:35:"hide_disabled_dates_from_datepicker";s:1:"1";s:34:"allow_checkout_first_disabled_date";s:1:"1";s:16:"payment_gateways";a:1:{s:6:"paypal";s:1:"1";}s:15:"default_gateway";s:6:"paypal";s:14:"paypal_message";s:54:"Pay with PayPal - The safer, easier way to pay online!";s:14:"stripe_message";s:45:"Pay with your credit or debit card via Stripe";s:19:"emails_admin_notice";s:19:"office@vilacoral.ro";s:16:"emails_from_name";s:10:"Casa Coral";s:25:"emails_from_email_address";s:19:"office@vilacoral.ro";s:11:"emails_type";s:4:"html";s:11:"emails_logo";s:55:"http://vilacoral.ro/wp-content/uploads/2017/05/logo.png";s:18:"emails_footer_text";s:58:"Termeni si conditii: www.vilacoral.ro/termeni-si-conditii/";s:30:"emails_new_reservation_enabled";s:1:"1";s:30:"emails_new_reservation_subject";s:51:"{site_title} - Rezervare noua #{reservation_number}";s:30:"emails_new_reservation_heading";s:14:"Rezervare noua";s:31:"emails_request_received_enabled";s:1:"1";s:31:"emails_request_received_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:31:"emails_request_received_heading";s:14:"Cerere primita";s:36:"emails_confirmed_reservation_enabled";s:1:"1";s:36:"emails_confirmed_reservation_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:36:"emails_confirmed_reservation_heading";s:29:"Va multumim pentru rezervare!";s:28:"emails_guest_invoice_subject";s:46:"Factura pentru rezervare #{reservation_number}";s:28:"emails_guest_invoice_heading";s:46:"Factura pentru rezervare #{reservation_number}";s:36:"emails_cancelled_reservation_enabled";s:1:"1";s:36:"emails_cancelled_reservation_subject";s:54:"{site_title} - Rezervare anulata #{reservation_number}";s:36:"emails_cancelled_reservation_heading";s:17:"Rezervare anulata";s:42:"emails_guest_cancelled_reservation_enabled";s:1:"1";s:42:"emails_guest_cancelled_reservation_subject";s:35:"Rezervarea dvs. pentru {site_title}";s:42:"emails_guest_cancelled_reservation_heading";s:17:"Rezervare anulata";s:22:"seasonal_prices_schema";a:37:{i:1;a:3:{s:4:"from";s:10:"2017-05-11";s:2:"to";s:10:"2017-05-12";s:5:"index";s:1:"1";}i:2;a:3:{s:4:"from";s:10:"2017-05-13";s:2:"to";s:10:"2017-05-14";s:5:"index";s:1:"2";}i:3;a:3:{s:4:"from";s:10:"2017-05-15";s:2:"to";s:10:"2017-05-19";s:5:"index";s:1:"3";}i:4;a:3:{s:4:"from";s:10:"2017-05-20";s:2:"to";s:10:"2017-05-21";s:5:"index";s:1:"4";}i:5;a:3:{s:4:"from";s:10:"2017-05-22";s:2:"to";s:10:"2017-05-26";s:5:"index";s:1:"5";}i:6;a:3:{s:4:"from";s:10:"2017-05-27";s:2:"to";s:10:"2017-05-28";s:5:"index";s:1:"6";}i:7;a:3:{s:4:"from";s:10:"2017-05-29";s:2:"to";s:10:"2017-06-02";s:5:"index";s:1:"7";}i:8;a:3:{s:4:"from";s:10:"2017-06-03";s:2:"to";s:10:"2017-06-04";s:5:"index";s:1:"8";}i:9;a:3:{s:4:"from";s:10:"2017-06-05";s:2:"to";s:10:"2017-06-09";s:5:"index";s:1:"9";}i:10;a:3:{s:4:"from";s:10:"2017-06-10";s:2:"to";s:10:"2017-06-11";s:5:"index";s:2:"10";}i:11;a:3:{s:4:"from";s:10:"2017-06-12";s:2:"to";s:10:"2017-06-16";s:5:"index";s:2:"11";}i:12;a:3:{s:4:"from";s:10:"2017-06-17";s:2:"to";s:10:"2017-06-18";s:5:"index";s:2:"12";}i:13;a:3:{s:4:"from";s:10:"2017-06-19";s:2:"to";s:10:"2017-06-23";s:5:"index";s:2:"13";}i:14;a:3:{s:4:"from";s:10:"2017-06-24";s:2:"to";s:10:"2017-06-25";s:5:"index";s:2:"14";}i:15;a:3:{s:4:"from";s:10:"2017-06-26";s:2:"to";s:10:"2017-06-30";s:5:"index";s:2:"15";}i:16;a:3:{s:4:"from";s:10:"2017-07-01";s:2:"to";s:10:"2017-07-02";s:5:"index";s:2:"16";}i:17;a:3:{s:4:"from";s:10:"2017-07-03";s:2:"to";s:10:"2017-07-07";s:5:"index";s:2:"17";}i:18;a:3:{s:4:"from";s:10:"2017-07-08";s:2:"to";s:10:"2017-07-09";s:5:"index";s:2:"18";}i:19;a:3:{s:4:"from";s:10:"2017-07-10";s:2:"to";s:10:"2017-07-14";s:5:"index";s:2:"19";}i:20;a:3:{s:4:"from";s:10:"2017-07-15";s:2:"to";s:10:"2017-07-16";s:5:"index";s:2:"20";}i:21;a:3:{s:4:"from";s:10:"2017-07-17";s:2:"to";s:10:"2017-07-21";s:5:"index";s:2:"21";}i:22;a:3:{s:4:"from";s:10:"2017-07-22";s:2:"to";s:10:"2017-07-23";s:5:"index";s:2:"22";}i:23;a:3:{s:4:"from";s:10:"2017-07-24";s:2:"to";s:10:"2017-07-28";s:5:"index";s:2:"23";}i:24;a:3:{s:4:"from";s:10:"2017-07-29";s:2:"to";s:10:"2017-07-30";s:5:"index";s:2:"24";}i:25;a:3:{s:4:"from";s:10:"2017-07-31";s:2:"to";s:10:"2017-08-04";s:5:"index";s:2:"25";}i:26;a:3:{s:4:"from";s:10:"2017-08-05";s:2:"to";s:10:"2017-08-06";s:5:"index";s:2:"26";}i:27;a:3:{s:4:"from";s:10:"2017-08-07";s:2:"to";s:10:"2017-08-11";s:5:"index";s:2:"27";}i:28;a:3:{s:4:"from";s:10:"2017-08-12";s:2:"to";s:10:"2017-08-13";s:5:"index";s:2:"28";}i:29;a:3:{s:4:"from";s:10:"2017-08-14";s:2:"to";s:10:"2017-08-18";s:5:"index";s:2:"29";}i:30;a:3:{s:4:"from";s:10:"2017-08-19";s:2:"to";s:10:"2017-08-20";s:5:"index";s:2:"30";}i:31;a:3:{s:4:"from";s:10:"2017-08-21";s:2:"to";s:10:"2017-08-25";s:5:"index";s:2:"31";}i:32;a:3:{s:4:"from";s:10:"2017-08-26";s:2:"to";s:10:"2017-08-27";s:5:"index";s:2:"32";}i:33;a:3:{s:4:"from";s:10:"2017-08-28";s:2:"to";s:10:"2017-09-01";s:5:"index";s:2:"33";}i:34;a:3:{s:4:"from";s:10:"2017-09-02";s:2:"to";s:10:"2017-09-03";s:5:"index";s:2:"34";}i:35;a:3:{s:4:"from";s:10:"2017-09-04";s:2:"to";s:10:"2017-09-08";s:5:"index";s:2:"35";}i:36;a:3:{s:4:"from";s:10:"2017-09-09";s:2:"to";s:10:"2017-09-10";s:5:"index";s:2:"36";}i:37;a:3:{s:4:"from";s:10:"2017-09-11";s:2:"to";s:10:"2018-02-28";s:5:"index";s:2:"37";}}s:22:"booking_months_advance";i:0;s:20:"booking_arrival_date";i:0;s:22:"booking_maximum_nights";i:0;s:21:"disabled_dates_schema";a:0:{}s:27:"room_unavailable_visibility";i:0;s:14:"paypal_sandbox";s:1:"1";s:20:"hotel_accepted_cards";a:4:{s:10:"mastercard";s:1:"1";s:4:"visa";s:1:"1";s:7:"maestro";s:1:"1";s:6:"visa_e";s:1:"1";}s:12:"paypal_email";s:0:"";s:17:"paypal_page_style";s:0:"";s:17:"stripe_form_image";s:0:"";s:22:"stripe_live_secret_key";s:0:"";s:27:"stripe_live_publishable_key";s:0:"";s:22:"stripe_test_secret_key";s:0:"";s:27:"stripe_test_publishable_key";s:0:"";s:10:"paypal_log";i:0;s:15:"stripe_testmode";i:0;s:10:"stripe_log";i:0;s:10:"terms_page";s:3:"521";s:28:"emails_guest_invoice_enabled";i:0;s:14:"hotel_postcode";s:0:"";s:9:"hotel_fax";s:0:"";s:18:"price_num_decimals";i:0;s:10:"hotel_pets";i:0;s:19:"enforce_ssl_booking";i:0;s:19:"unforce_ssl_booking";i:0;}
当我尝试将日期打印为表格时,我会使用以下错误:
while($row = mysqli_fetch_array($result)){
$mydata = $row['option_value'];
$data = unserialize($mydata);
$tabel = $data['seasonal_prices_schema'];
foreach($tabel as $linie) {
$from = $linie['from'];
$to = $linie['to'];
echo '<tr>';
echo '<td>' . $from . '</td>';
echo '<td>' . $to . '</td>';
echo '</tr>';
}
}
错误是:警告:foreach()
x.php on line 102
提供的参数无效
-> foreach($tabel as $linie)
当我将以下存储日期粘贴到$ mydata ='';它打印出来,但是当我把db中的信息放在工作中时。
对不起我的英文,如果你有任何想法。
编辑:
我想我认为为什么不工作,首先它dosnt将它视为一个数组,如果从数据库中获取它,如果我从$ mydata上的数据库复制粘贴它打印表。我认为问题是:3:“m²”;那个“2”。
THE FIX: 在连接到DB之后我把它放了。并用“m²”修正了问题
if($link->set_charset("utf8")){
// rest of the code
}
感谢
答案 0 :(得分:0)
这里很容易解释。你的字符串是:s:22:"seasonal_p...
,说的是:带有22个字符和内容的字符串......
因此,这不是一个可以循环的数组。
要反序列化数组,您的字符串必须以:a:32:{s:22:...}
开头,因此在这种情况下,数据库中的strign可能会被破坏。
只需在发布字符串的情况下尝试https://de.functions-online.com/unserialize.html,您就会看到它只返回一个字符串。
顺便说一句:unserialize函数在出错时返回false。所以你不能在两者之间分开:
$val = unserialize(serialize(false));
和
$val = unserialize('##'); //invalid string
<强>更新强>
再次,查看结果可以发现会发生什么:现在您正在反序列化一个数组,但是它是嵌套的并且包含其他带有数字或字符串键的数组,因此您不能将数组用作字符串。