Mysql如何改变变量

时间:2018-04-08 15:25:37

标签: mysql

我的问题是:

$channeldb = mysql_query("SELECT * FROM channels AS ch
            LEFT JOIN groups AS gr 
            ON gr.code = ch.code
            ". $searchdb ." LIMIT 100");
while($channel = mysql_fetch_assoc($channeldb))
...

变量$ cannel [id]来自表组,但我需要来自频道

像这样:

$ch-id = ch.id;

但是如何:)

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

明确选择所需的列。例如:

vatA

对于应用程序代码,您不应该使用##import and initiate pygame import pygame as pg pg.init() ##Set display dimensions and the button size as a function of these dimensions. display_width = 400 display_height = 600 buttonSize = (display_width/4) ##Create game display surface. gameDisplay = pg.display.set_mode((display_width,display_height)) white = (255,255,255) ##posList holds nine pairs of X,Y multipliers. These are multiplied by buttonSize to draw the grid. posList = ((0.25,0.25), (0.25,1.5), (0.25,2.75), (1.5,0.25), (1.5,1.5), (1.5,2.75), (2.75,0.25), (2.75,1.5), (2.75,2.75)) ##board is a list of nine lists. Each nested list holds the butttons that switched by each button press. board = ((0,1,3),(1,0,2,4),(2,1,5),(3,4),(4,1,7),(5,4),(6,3,7),(7,4,6,8),(8,5,7)) ##I import the button image redSquare = pg.image.load('Button Image.png').convert() redSquare = pg.transform.scale(redSquare, (int(buttonSize), int(buttonSize))) ##The Button class holds coordinate, image and controls attributes class Button: def __init__(self, x, y, image, controls, green = False): self.x = x self.y = y self.image = image self.isgreen = green self.controls = controls ##It has a blit method. def buttonBlit(self): gameDisplay.blit(self.image, (self.x, self.y)) ##I create an empty list called buttons. buttons = [] ##I populate buttons by looping through the Button class 9 times. for i in range(9): buttons.append(Button(posList[i][0] * buttonSize, posList[i][1] * buttonSize, redSquare, board[i])) ##The blit method draws the buttons. gameDisplay.fill(white) for button in buttons: Button.buttonBlit(button) pg.display.update() ##I can reference each button by using the index in the buttons list. Furthermore, I can use buttons[i].controls to perform the actions of a button press. (至少)四个原因:

  • 如果基础表发生更改,则会影响您的代码(这很难调试)。
  • 如果表格具有相同的列,则会产生混淆。
  • 带回额外的未使用的列只是浪费带宽(因此浪费时间)。
  • 您的代码应该非常清楚它正在使用的数据。

如果你需要两个ID,那么别名:

SELECT ch.id
FROM channels ch LEFT JOIN
     groups gr 
     ON gr.code = ch.code;

此外,如果您在每个表中都有唯一ID,则应该将其用于SELECT *,而不是SELECT ch.id as channel_id, gr.id s group_id FROM channels ch LEFT JOIN groups gr ON gr.code = ch.code;

答案 1 :(得分:0)

使用渠道中的select id,然后查询将返回渠道中的ID