par
superNoob » 10 août 2020, 00:27
Bonsoir,
revoilà le code qui me pose problème,...
Lorsque je fais un var_dump après "to_ret", j'obtiens bien l'array de la première photo !
array(1) { [0]=> array(11) { ["id"]=> string(2) "17" ["title"]=> string(12) "Our holidays" ["width"]=> string(3) "128" ["height"]=> string(3) "128" ["tag"]=> string(8) "holidays" ["filename"]=> string(21) "holidays/holidays.jpg" ["price"]=> string(2) "15" ["high_quality"]=> string(12) "NDMzMzY2NQ==" ["created_on"]=> string(19) "2020-01-28 22:15:05" ["user_id"]=> string(1) "9" ["login"]=> string(5) "wanda" } }
Je me suis sûrement trompé dans le fichier get_recent pictures ne possédant pas assez d'expérience en php, en effet, voici le code
Code : Tout sélectionner
function get_recent_pictures($db, $limit = 10){
$sql = $db->query("SELECT p.*,u.login from `pictures` p left join users u on u.id = p.user_id order by created_on DESC limit 3, 10;", [$limit])->fetch(PDO::FETCH_ASSOC);
if ($sql)
{
$row = array();
while ($row = $sql)
{
$to_ret[] = $row;
var_dump($to_ret);
die();
break;
}
return $to_ret;
}
else
{
return False;
}
}
Lorsque je le modifie, j'ai de temps en temps une erreur 'undefined index for id ... title ...'
Merci de votre aide, j'espère comprendre cela avec votre aide car là je coince,... Merci

Bonsoir,
revoilà le code qui me pose problème,...
Lorsque je fais un var_dump après "to_ret", j'obtiens bien l'array de la première photo !
array(1) { [0]=> array(11) { ["id"]=> string(2) "17" ["title"]=> string(12) "Our holidays" ["width"]=> string(3) "128" ["height"]=> string(3) "128" ["tag"]=> string(8) "holidays" ["filename"]=> string(21) "holidays/holidays.jpg" ["price"]=> string(2) "15" ["high_quality"]=> string(12) "NDMzMzY2NQ==" ["created_on"]=> string(19) "2020-01-28 22:15:05" ["user_id"]=> string(1) "9" ["login"]=> string(5) "wanda" } }
Je me suis sûrement trompé dans le fichier get_recent pictures ne possédant pas assez d'expérience en php, en effet, voici le code
[code] function get_recent_pictures($db, $limit = 10){
$sql = $db->query("SELECT p.*,u.login from `pictures` p left join users u on u.id = p.user_id order by created_on DESC limit 3, 10;", [$limit])->fetch(PDO::FETCH_ASSOC);
if ($sql)
{
$row = array();
while ($row = $sql)
{
$to_ret[] = $row;
var_dump($to_ret);
die();
break;
}
return $to_ret;
}
else
{
return False;
}
}[/code]
Lorsque je le modifie, j'ai de temps en temps une erreur 'undefined index for id ... title ...'
Merci de votre aide, j'espère comprendre cela avec votre aide car là je coince,... Merci :D