只回显第一列,而不是全部

时间:2018-09-23 21:27:17

标签: php

这是怎么了:

def javaq(request):
    user_attended_questions = # get a list of user attended question ids here
    context = {
        'query_results' : JAVATEST.objects.exclude(id__in=user_attended_questions).first() # excluding the questions user already attended and picking the first question from the remaining queryset 
    }
    return render(request, 'javaq.html',context)

结果:

$itemsa = "date, name, phone, address, color, height";

function users($id) {
    global $db;
    global $_POST;
    global $itemsa;
    $sql = "select *  from users where id = :aid limit 1";
    $st = $db->prepare($sql);
    $st -> execute([":aid" => $id]);
    $arra = explode(', ', $itemsa);
    $items = "";
    $x = 0;
    while ($row = $st->fetch()) {
        $items .=
        "<div class='rtitle' data-id = " . $row['id'] . ">" . mb_strtoupper($arra[$x]) . "</div>\n" .
        "<div class='rstory' data-id = " . $row['id'] . ">" . $row[$x] . "</div>\n";
        $x++;
    }
    echo $items;
}

所以只回显第一列,我希望它们都是6。

1 个答案:

答案 0 :(得分:1)

您应该在传递给函数的列名数组上循环,而不是在获取结果上循环,因为您仅从查询返回ONE ROW,并且对该行中返回的列感兴趣。

您还应该将所有这些全局变量(无论如何$ _POST都是全局变量,无论如何都不会在函数中使用)作为参数传递给函数调用。

var socket = null;

function startSocketServer(){
    //Socket.io
  const express = require('express');
  const socketIO = require('socket.io');
  const https = require('https');
  const socketPort = 3000;
  const fs = require('fs');
  const path = require('path');


  var options = {
    key: fs.readFileSync(path.resolve(__dirname, '/etc/letsencrypt/live/sitedomain/privkey.pem')),
    cert: fs.readFileSync(path.resolve(__dirname, '/etc/letsencrypt/live/sitedomain/fullchain.pem')),
  };

  var socketServer = https.createServer(options, express()).listen(socketPort, function() {
    console.log("socketServer listening on port " + socketPort);
  });

  socket = socketIO(socketServer);

  socket.on('connection', (socket) => {
    console.log('Client connected');
    socket.on('disconnect', () => console.log('Client disconnected'));
  });

}