I'm looking to loop the following script, as to save lines of code, and manual hardcoding. The script pulls specific values from my database and assigns them to variables that are used across my website.
$w1001a = $conn->query("SELECT columnB FROM table WHERE columnA='w1001a' limit 1")->fetch_object()->content; $w1001b = $conn->query("SELECT columnB FROM table WHERE columnA='w1001b' limit 1")->fetch_object()->content; .... $w1025b = $conn->query("SELECT columnB FROM table WHERE columnA='w1001b' limit 1")->fetch_object()->content;
Thanks in advance!
Don't loop the query, use one query to get all the info.
The below is just dummy code:
$stmt = $conn->query("SELECT columnA, columnB FROM table WHERE columnA IN ('w1001a', 'w1001b', ...)");
$result = array();
while ($obj = $stmt->fetch_object()) {
$result[$obj->columnA] = $obj->columnB;
}