mysql从表中获取行值,其中列值等于特定值

时间:2017-07-06 12:25:22

标签: php mysql

我有一个表格,其中modeltest的结果按降序排列在列中。现在我想获取特定行的行号。以下是示例表:

enter image description here

所以当我用userid = 44搜索a时,它应该返回3.再次当我用userid = 11搜索时,它应该返回4.我怎么能这样做?如果有人可以帮助我。

2 个答案:

答案 0 :(得分:0)

一个简单的where子句将实现这一点。

        // Determine the needed width and height of TimeCircles
        var height = this.element.offsetHeight;
        var width = this.element.offsetWidth;
        if (height === 0)
            height = $(this.element).height();
        if (width === 0)
            width = $(this.element).width();

        if (height === 0 && width > 0)
            height = width / this.data.drawn_units.length;
        else if (width === 0 && height > 0)
            width = height * this.data.drawn_units.length;
        
        // Create our canvas and set it to the appropriate size
        var canvasElement = document.createElement('canvas');
        canvasElement.width = width;
        canvasElement.height = height;
        
        // Add canvas elements
        this.data.attributes.canvas = $(canvasElement);
        this.data.attributes.canvas.appendTo(this.container);
        
        // Check if the browser has browser support
        var canvasSupported = isCanvasSupported();
        // If the browser doesn't have browser support, check if explorer canvas is loaded
        // (A javascript library that adds canvas support to browsers that don't have it)
        if(!canvasSupported && typeof G_vmlCanvasManager !== "undefined") {
            G_vmlCanvasManager.initElement(canvasElement);
            limited_mode = true;
            canvasSupported = true;
        }
        if(canvasSupported) {
            this.data.attributes.context = canvasElement.getContext('2d');
        }

        this.data.attributes.item_size = Math.min(width / this.data.drawn_units.length, height);
        this.data.attributes.line_width = this.data.attributes.item_size * this.config.fg_width;
        this.data.attributes.radius = ((this.data.attributes.item_size * 0.8) - this.data.attributes.line_width) / 2;
        this.data.attributes.outer_radius = this.data.attributes.radius + 0.5 * Math.max(this.data.attributes.line_width, this.data.attributes.line_width * this.config.bg_width);

将表和userid值交换为所需的值。

希望这有帮助

答案 1 :(得分:0)

例如:

$stmt = PDO::prepare('SELECT id FROM table WHERE userid = ?');
$userId = 44;

$stmt->execute([$userId]);
$result = $stmt->fetch(PDO::FETCH_OBJ);

echo $result->id;

http://php.net/manual/en/book.pdo.php