Table structure
ID KEY VAL
1 Sex Male
2 Day 365
4 Num 12345
Now I want the echo $a [' sex '] on this page to display the male echo $a [' Day '] to show 365
PHP query MySQL statement how to write convenient at any time echo it?
Reply to discussion (solution)
Pre -function Select_db_col ($sql _string) { unset ($this->records); @mysql_free_result ($this->result); $this->result= @mysql_query ($sql _string, $this->db), $i =1;while ($temp _rows= @mysql_fetch_array ($this result, Mysql_assoc) {for ($j =0; $j
result, $j) $this->records["$temp _key_name" [$i] = $temp _rows["$ Temp_key_name "];} $i + +;} return $this->records; }
This is written as column output, formatted as $var[column [row]
And then
$a =array_combine ($var [' KEY '], $var [' VAL '];
To implement in MySQL, you need to write a stored procedure
You search for "crosstab", you can find multiple versions of the implementation algorithm
If implemented in PHP, it can be constructed when the query results are read
while ($row = Mysql_fetch_assoc ($rs)) {
$a [$row [' key ']] = $row [' Val '];
}
The second floor is mighty, so complex a problem a line of code to fix.