Пользователь 1 — Джонни. Пользователь 2 — Билли. Билли может следовать за Джонни, но когда Джонни пытается следовать за Билли, я получаю сообщение об ошибке. Я просматривал свой код снова и снова, но не смог найти проблему. Всплывает ошибка:
Неустранимая ошибка: Uncaught TypeError: array_column(): Аргумент № 1 ($array) должен иметь тип массива, указанный в значении null. C:\xampp\htdocs\Project\classes\post.classes.php:365 Трассировка стека: #0 C:\xampp\htdocs\Project\classes\post.classes.php(365): array_column(NULL, 'userid') #1 C:\xampp\htdocs\Project\like.php(33): Post->like_post ('98168', 'пользователь', '7500') #2 C:\xampp\htdocs\Project\index.php(23): require('C:\xampp\htdocs...') #3 {main}, добавленный в C:\xampp\htdocs\Project\classes\post.classes.php в строке 365
public function follow_user($id,$type,$mfg_userid){
if($id == $mfg_userid && $type == 'user'){
return;
}
$DB = new Database();
$sql = "select following from likes where type='$type' && contentid = '$mfg_userid' limit 1";
$result = $DB->read($sql);
if(is_array($result)) {
$likes = json_decode($result[0]['following'],true);
$user_ids = array_column($likes, "userid");
if(!in_array($id, $user_ids)) {
$arr["userid"] = $id;
$arr["date"] = date("Y-m-d H:i:s");
$likes[] = $arr;
$likes_string = json_encode($likes);
$sql = "update likes set following = '$likes_string' where type='$type' && contentid = '$mfg_userid' limit 1";
$DB->save($sql);
$user = new User();
$single_post = $user->get_user($id);
add_notification($_SESSION['mfg_userid'],"follow",$single_post);
} else {
$key = array_search($id, $user_ids);
unset($likes[$key]);
$likes_string = json_encode($likes);
$sql = "update likes set following = '$likes_string' where type='$type' && contentid = '$mfg_userid' limit 1";
$DB->save($sql);
}
} else {
$arr["userid"] = $id;
$arr["date"] = date("Y-m-d H:i:s");
$arr2[] = $arr;
$following = json_encode($arr2);
$sql = "insert into likes (type,contentid,following) values ('$type','$mfg_userid','$following')";
$DB->save($sql);
$user = new User();
$single_post = $user->get_user($id);
add_notification($_SESSION['mfg_userid'],"follow",$single_post);
}
}
Подробнее здесь: https://stackoverflow.com/questions/715 ... -typeerror
Продолжайте получать Uncaught TypeError ⇐ Php
Кемеровские программисты php общаются здесь
1732313044
Anonymous
Пользователь 1 — Джонни. Пользователь 2 — Билли. Билли может следовать за Джонни, но когда Джонни пытается следовать за Билли, я получаю сообщение об ошибке. Я просматривал свой код снова и снова, но не смог найти проблему. Всплывает ошибка:
Неустранимая ошибка: Uncaught TypeError: array_column(): Аргумент № 1 ($array) должен иметь тип массива, указанный в значении null. C:\xampp\htdocs\Project\classes\post.classes.php:365 Трассировка стека: #0 C:\xampp\htdocs\Project\classes\post.classes.php(365): array_column(NULL, 'userid') #1 C:\xampp\htdocs\Project\like.php(33): Post->like_post ('98168', 'пользователь', '7500') #2 C:\xampp\htdocs\Project\index.php(23): require('C:\xampp\htdocs...') #3 {main}, добавленный в C:\xampp\htdocs\Project\classes\post.classes.php в строке 365
public function follow_user($id,$type,$mfg_userid){
if($id == $mfg_userid && $type == 'user'){
return;
}
$DB = new Database();
$sql = "select following from likes where type='$type' && contentid = '$mfg_userid' limit 1";
$result = $DB->read($sql);
if(is_array($result)) {
$likes = json_decode($result[0]['following'],true);
$user_ids = array_column($likes, "userid");
if(!in_array($id, $user_ids)) {
$arr["userid"] = $id;
$arr["date"] = date("Y-m-d H:i:s");
$likes[] = $arr;
$likes_string = json_encode($likes);
$sql = "update likes set following = '$likes_string' where type='$type' && contentid = '$mfg_userid' limit 1";
$DB->save($sql);
$user = new User();
$single_post = $user->get_user($id);
add_notification($_SESSION['mfg_userid'],"follow",$single_post);
} else {
$key = array_search($id, $user_ids);
unset($likes[$key]);
$likes_string = json_encode($likes);
$sql = "update likes set following = '$likes_string' where type='$type' && contentid = '$mfg_userid' limit 1";
$DB->save($sql);
}
} else {
$arr["userid"] = $id;
$arr["date"] = date("Y-m-d H:i:s");
$arr2[] = $arr;
$following = json_encode($arr2);
$sql = "insert into likes (type,contentid,following) values ('$type','$mfg_userid','$following')";
$DB->save($sql);
$user = new User();
$single_post = $user->get_user($id);
add_notification($_SESSION['mfg_userid'],"follow",$single_post);
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/71537438/keep-getting-uncaught-typeerror[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия