gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
Исправь код, не видит базу данных таблицу catalog, выдаёт: Ошибка синтаксического…
- User
Исправь код, не видит базу данных таблицу catalog, выдаёт: Ошибка синтаксического анализа : синтаксическая ошибка, неожиданный T_CONST, ожидание T_VARIABLE в Z:\home\localhost\www\Clothes.ru\classes\PdoConnect.php Код: Каталог <div class="product-pic" руб. Купить
- Assistant
Ошибка синтаксического анализа возникает из-за неправильно расставленных открывающих и закрывающих скобок при объявлении функции secondToDate.
Вот исправленный код:
<?php spl_autoload_register(function ($class) { include 'classes/' . $class . '.php'; }); function secondToDate($mounth, $day) { $currentDate = date('Y.m.d.H.i.s', time()); $currentDateArray = explode('.', $currentDate); if ($currentDateArray[1] > $mounth || ($currentDateArray[1] == $mounth && $currentDateArray[2] > $day)) { $year = $currentDateArray[0] + 1; } elseif ($currentDateArray[1] == $mounth && $currentDateArray[2] == $day) { return 0; } else { $year = $currentDateArray[0]; } $dateFrom = date_create($currentDateArray[0] . "-" . $currentDateArray[1] . "-" . $currentDateArray[2] . " " . $currentDateArray[3] . ":" . $currentDateArray[4] . ":" . $currentDateArray[5]); $dateTo = date_create($year . "-" . $mounth . "-" . $day); $diff = date_diff($dateTo, $dateFrom); return ($diff->y * 365 * 24 * 60 * 60) + ($diff->m * 30 * 24 * 60 * 60) + ($diff->d * 24 * 60 * 60) + ($diff->h * 60 * 60) + ($diff->i * 60) + $diff->s; } $secondTo = secondToDate(12, 24); $currentDate = date('m.d', time()); $currentDateArray = explode('.', $currentDate); $currentMounth = $currentDateArray[0]; $currentDay = $currentDateArray[1]; $currentMounth = 12; $currentDay = 24; if ($currentMounth == 12 && $currentDay >= 24) { $PDO = PdoConnect::getInstance(); $result = $PDO->PDO->query(" SELECT * FROM catalog"); $products = array(); while ($productInfo = $result->fetch()) { $products[] = $productInfo; } include 'index.php'; } else { include 'timer.php'; } ?> <section class="product-box"> <h2>Каталог</h2> <div class="row"> <?foreach ($products as $product):?> <div class="col-xs-6 col-sm-4 col-md-3 col-lg-3 product-parent" data-id="<?=$product['N_tovar']?>"> <div class="product"> <div class="product-pic"> <span class="product-name"><?=$product['Nazvanie']?></span> <span class="product_price"><?=$product['Price']?> руб.</span> <button class="js_buy">Купить</button> </div> </div> </div> <?endforeach;?> </div> </section>
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.