如何从DB填充选择选项

时间:2015-08-26 21:58:43

标签: php mysqli

我在这里做错了什么?当它填充选项时,它显示$ name [0]而不是DB中的信息。虽然似乎有正确数量的选项。

# generating some test data
timestamp = [1440540000, 1450540000]
df1 = pd.DataFrame(
    {'timestamp': timestamp, 'a': ['val_a', 'val2_a'], 'b': ['val_b', 'val2_b'], 'c': ['val_c', 'val2_c']})
# building a different index
timestamp = timestamp * np.random.randn(abs(1))
df2 = pd.DataFrame(
    {'timestamp': timestamp, 'd': ['val_d', 'val2_d'], 'e': ['val_e', 'val2_e'], 'f': ['val_f', 'val2_f'],
     'g': ['val_g', 'val2_g']}, index=index)
# keeping a value in common with the first index
timestamp = [1440540000, 1450560000]
df3 = pd.DataFrame({'timestamp': timestamp, 'h': ['val_h', 'val2_h'], 'i': ['val_i', 'val2_i']}, index=index)

# Setting the timestamp as the index
df1.set_index('timestamp', inplace=True)
df2.set_index('timestamp', inplace=True)
df3.set_index('timestamp', inplace=True)

# You can convert timestamps to dates but it's not mandatory I think
df1.index = pd.to_datetime(df1.index, unit='s')
df2.index = pd.to_datetime(df2.index, unit='s')
df3.index = pd.to_datetime(df3.index, unit='s')

# Just perform a join and that's it
result = df1.join(df2, how='outer').join(df3, how='outer')
result

1 个答案:

答案 0 :(得分:2)

在php中,有两种类型的引号:单引号和双引号。单引号不会解析变量,双引号会。

如果你想使用引号,你可以这样做:

echo "<option value="."$name[1]".">$name[0]</option>";

所以在这里,双引号会告诉php解析变量名

但是,我建议这样做:

echo '<option value="' . $name[1] . '">' . $name[0] . '</option>';

有关详情,请参阅this SO帖子。