1

I've been trying to make a simple video list system for my website, and I can't get this working.

    $buffer = explode("|", $playlist['videos']);
    $id = 0;

    foreach($buffer as $key) { 
        if(!empty($key)) {
            $id++;
            $video = getVideoFromId($key, $conn); 
            print_r($video);

getVideoFromId

function getVideoFromId($id, $connection) {
    $stmt = $connection->prepare("SELECT * FROM videos WHERE rid = ?");
    $stmt->bind_param("s", $id);
    $stmt->execute();
$result = $stmt->get_result();
$video = $result->fetch_assoc();
$stmt->close();

return $video;
}

It seems to completely ignore it, buffer is not empty because when I print_r'd it, it outputted the stuff that I needed. $playlist is a function named getPlaylistFromID.

getPlaylistFromId

function getPlaylistFromID($id, $connection) {
    $stmt = $connection->prepare("SELECT * FROM playlists WHERE rid = ?");
    $stmt->bind_param("s", $id);
    $stmt->execute();
$result = $stmt->get_result();
$playlist = $result->fetch_assoc();
$stmt->close();

return $playlist;
}

$key is the video ID, and $video is an array of the video containing all the data like the title, description, and whatnot.

$buffer is usually a video id seperated by |, for example: |MTYxMTUxNzE2MzQ=47|MTYxMTUxNzE2MzQ=47|MTYxMTUxNzE2MzQ=47|MTYxMTUxNzE2MzQ=47|MTYxMTUxNzE2MzQ=47|MTYxMTUxNzE2MzQ=47 is the format it is in.

  • is `$buffer` an array? you need to `explode` the separator before using the `$key`. you try to echo `$key`, it will not be what you want – zimorok Feb 03 '21 at 07:21
  • $buffer is a string that's supposed to be seperated by the character ``|``, and I ``explode`` it so I can use it in a foreach. – chiefnbiazon Feb 03 '21 at 07:25
  • @chiefnbiazon: echo the `$key` to see if it contain the actual data from the `$buffer` – zimorok Feb 03 '21 at 07:28
  • No error at all, which is what I'm confused about. print_r'ing $video absolutely does nothing. – chiefnbiazon Feb 03 '21 at 07:28
  • I did echo $key, it does have the data from $buffer. – chiefnbiazon Feb 03 '21 at 07:29
  • Most likely your query failed. See here on [finding out the actual mysqli error](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param). – El_Vanja Feb 03 '21 at 09:44
  • Using ``mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);`` still doesn't echo any errors. I'm starting to think this is an internal PHP issue. I'm using PHP 7.4 – chiefnbiazon Feb 03 '21 at 19:47
  • @chiefnbiazon did you tried what I have told you? add `error_reporting(E_ALL);ini_set('display_errors',1);` before `$buffer = explode("|", $playlist['videos']);` and run your code – Alive to die - Anant Feb 04 '21 at 06:22
  • Yes. I have. No errors though. – chiefnbiazon Feb 04 '21 at 21:27

0 Answers0