我需要返回mysql查询
来自
class MyComponent extends React.Component {
ref = React.createRef();
componentDidMount() {
this.onChangeMade();
}
onChangeMade = () => {
const { current } = this.ref;
const scrollHeightPadded = current.scrollHeight;
if (scrollHeightPadded + "px" !== current.style.height) {
current.style.height = 0;
const height = Math.max(scrollHeightPadded, 31) + 3;
current.style.height = `${height}px`;
}
};
render() {
return (
<div className={`resizable-textbox ${className}`}>
<textarea
ref={this.ref}
value={value}
onChange={onChangeMade}
onBlur={onBlur}
readOnly={readOnly}
/>
</div>
);
}
}
但是我需要在mysql中这样返回(我将它写在数组中,因为它很容易写)
SELECT name as id FROM table
答案 0 :(得分:1)
使用WHERE
条件
SELECT * FROM table WHERE ID = yourId
只需将yourId
替换为所需的ID号。
答案 1 :(得分:0)
答案 2 :(得分:0)
首先,使用
选择所有ID和名称SELECT id, name FROM table SOME CONDITIONS
此查询将返回类似的结果
$result = [
[ id => 1, name => 'name' ],
[ id => 1, name => 'name' ],
[ id => 1, name => 'name' ],
[ id => 1, name => 'name' ],
]
然后排列数组
$accepted_output = array_column($result, 'id', 'name')
$accepted_output = [
[ 1 => 'name' ],
[ 1 => 'name' ],
[ 1 => 'name' ],
[ 1 => 'name' ],
]
array_column文档-https://www.php.net/manual/en/function.array-column.php