关联数组的基本查询

时间:2019-07-09 04:02:54

标签: php mysql

如何查询呢?

图形正在处理该查询

$dataPoints = array();

$result = mysqli_query($conn, "SELECT * FROM service_booking GROUP BY service_id");

while($row = mysqli_fetch_array($result))
{        
    $point = array("label" => $row['service_id'] , "y" => $row['booking_id']);

    array_push($dataPoints, $point);        
}

但是我希望“标签” $row['service_id']显示为来自另一父表的['services']

  services (tbl1)                            service_booking (tbl2) 
 services || service_id                     service_id ||  booking id

1 个答案:

答案 0 :(得分:1)

加入表格

#You can use zip with itertools.cycle() to cycle thru the smallest list/Series

df1 = pd.Series(data=['a','b','c'],name='my_values')
df2 = pd.Series(data= 'red','orange','yellow','green','blue','indigo','violet','maroon','brown','black'], name='color')

import itertools

df2 = pd.concat([df2, pd.Series([b for a,b in zip(df2 , itertools.cycle(df1))], name='my_value')],axis=1)
df2


   color    my_value
0   red     a
1   orange  b
2   yellow  c
3   green   a
4   blue    b
5   indigo  c
6   violet  a
7   maroon  b
8   brown   c
9   black   a