douyi4544 2016-02-22 11:30
浏览 44

too long

I want to transform this PHP function.. that should return JSON data.

<?php
$query = 'SELECT * FROM `' . mix_player::table() . '` a';
if (isset($_GET['cat']) || isset($_GET['order'])) 
    if (isset($_GET['cat'])) {
        $query .= ' INNER JOIN `' . mix_player::table_cat_rel() . '` b '
            . "ON (a.`id` = b.`idtrack`) WHERE `idcat` = '" . $wpdb->escape($_GET['cat']) . "'";

        $random = $wpdb->get_var('SELECT `random`, `order` FROM `' . mix_player::table_categories() . "` WHERE `id` = '"
            . $wpdb->escape($_GET['cat']) . "'");

        if (!$random)
            $order = $wpdb->get_var(NULL, 1);
    }

    if (isset($_GET['order']))
        $order = $_GET['order'];

    if ($order != '') {
        if (isset($_GET['cat']))
            $query .= ' AND ';
        else
            $query .= ' WHERE ';

        $tracks = mix_player::order_list($query, $order);
    }

} else {
    $random = '0';
}

$query .= ' ORDER BY `id` ASC';

if (isset($tracks) || ($tracks = $wpdb->get_results($query, ARRAY_A))) {
    // option "shuffle = true" not always working into mix. Do it our own way...
    if ($random == 1) { // shuffle tracks?
        list($usec, $sec) = explode(' ', microtime());
        mt_srand((float) $sec + ((float) $usec * 100000));
        $nrows = count($tracks);
        for ($i = 0; $i < $nrows; $i++) {
            $j = mt_rand(0, $nrows - 1);  // pick j at random
            $row = $tracks[$i]; // swap i, j
            $tracks[$i] = $tracks[$j];
            $tracks[$j] = $row;
        }
    }

    foreach ($tracks as $row) {


        $artist = (mix_player::entities($row['artist']));
        echo ($artist);


        $title = (mix_player::entities($row['title']));

        echo ($title);

        $url =(xspf_player::entities($row['url']));
        echo ($url);        

}
}
?>

to display like this json file :

{"title":"title", "artist":"artist","media":"url media.mp3","color":"#56B0E8" },

Can you help me?

Thanks in advance.

</div>
  • 写回答

2条回答 默认 最新

  • dthtvk3666 2016-02-22 11:39
    关注
    echo json_encode(array("title"=>$title,"artist"=>$artist,"url"=>$url));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题