douti0687 2014-12-07 06:32
浏览 46

Mysql SELECT WHERE id = array()

Im trying to insert an array into a SELECT WHERE id = array() and im trying to show the results in a table,i can get one row of data, the first teams name,wins,and losses, but the remaining 4 teams do not appear.Im trying to show all teams where there id's are equal to the array.

$tournament = mysql_query("SELECT * FROM `tournaments` WHERE `id` = ".((int)$slug[1])." LIMIT 1");
    if (mysql_num_rows($tournament) > 0) {
        $tournament = mysql_fetch_assoc($tournament);
    }
    //array is equal to 273,287,234,423,124
    $teamx = array();
    $teamx[] = $tournament['teams'];

    $tteams = mysql_query("SELECT * FROM `teams` WHERE `id` IN (" . implode(',', array_map('intval', $teamx)) . ") LIMIT 128");
    if (mysql_num_rows($tteams) > 0) {
        $tteams = mysql_fetch_assoc($tteams);
        $template['TOURNAMENTTEAMS'] .= '<tr><td style="text-align: center;"><strong>' .$tteams['name']. '</td><td style="text-align: center;">' .$tteams['wins']. '</td><td style="text-align: center;">' .$tteams['losses']. '</td></tr>';
    }else{
        $template['TOURNAMENTTEAMS'] .= '<tr><td style="text-align: center;"><strong>No eligible teams.</td><td style="text-align: center;"></td><td></td></tr>';
    }`
  • 写回答

3条回答 默认 最新

  • doufen3838 2014-12-07 06:38
    关注

    You need to loop through your results, right now you if you get 1 or 10 results, you only print the first item.

    if (mysql_num_rows($tteams) > 0) {
        $results = mysql_fetch_assoc($tteams);
        foreach($results as $row) {
            $template['TROURNAMENTTEAMS'] .= ... ;
        }
    } else {
        $template['TROURNAMENTTEAMS'] .= ... ;
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏