PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE my_table ( id INT AUTO_INCREMENT, state VARCHAR(100), link VARCHAR(100), PRIMARY KEY (id) ); INSERT INTO my_table(id, state, link) VALUES (1, 'Alabama', 'auburn.alabama.com'), (2, 'Alabama', 'bham.alabama.com'), (3, 'Alabama', 'dothan.alabama.com');
Copy Clear
Copy Format Clear
<?php // $mysqli is already declared as a working database connection by this sandbox $result = []; foreach ($mysqli->query('SELECT * FROM my_table') as ['link' => $link, 'state' => $result[$link]]); var_export($result); echo $result['auburn.alabama.com'];
Show:  
Copy Clear