Answer the question
In order to leave comments, you need to log in
How in PHP write a for() loop to an array and output its variable?
With this I pull data from mysql
$result=mysql_query("SELECT id,address,phone,delivery_id FROM s_orders WHERE status = '0' AND paid = '1' AND delivery_id != '5' ORDER BY phone");
echo "<table border=1>";
for($i=0;$i<$n;$i++) echo "<tr><td>",mysql_result($result,$i,"id"),"</td><td>",mysql_result($result,$i,"address"),"</td><td>",mysql_result($result,$i,"phone"),"</td></tr>";
echo "</table>";
mysql_close($db);
$addrbook_id = "2321321";
$res = $Stat->createCampaign("testName",
"Адреса заказов: $fst",
$addrbook_id, "", 0, 0, 0, "");
Answer the question
In order to leave comments, you need to log in
It should be something like this:
$rows=array();
$result=mysql_query("SELECT id,address,phone,delivery_id FROM s_orders WHERE status = '0' AND paid = '1' AND delivery_id != '5' ORDER BY phone");
for($i=0;$i<$n;$i++) {
$row=array("id" => mysql_result($result,$i,"id"),
"address" => mysql_result($result,$i,"address"),
"phone" => mysql_result($result,$i,"phone")
);
array_push($rows, $row);
}
mysql_close($db);
$addrs=array();
$result=mysql_query("SELECT id,address,phone,delivery_id FROM s_orders WHERE status = '0' AND paid = '1' AND delivery_id != '5' ORDER BY phone");
for($i=0;$i<$n;$i++) {
array_push($addrs, mysql_result($result,$i,"address"));
}
mysql_close($db);
$Stat->createCampaign("testName",
"Адреса заказов: $addrs",
$addrbook_id, "", 0, 0, 0, "");
$Stat->createCampaign("testName",
"Адреса заказов: " . implode(',', $addrs),
$addrbook_id, "", 0, 0, 0, "");
Well, I'll start with the fact that mysql_query is deprecated, that is, for God's sake, don't use this extension. Only mysqli or pdo.
Well, I’ll end up with the fact that you first need to collect the data into an array (there are guidelines in the documentation) and then do anything with this array. For example:$addresses = array_column($rows, 'address');
If you are using mysql_*, which is no longer supported and considered unsafe.
i.e. special function - mysql_fetch_assoc
$result = mysql_query("SELECT id,address,phone,delivery_id FROM s_orders WHERE status = '0' AND paid = '1' AND delivery_id != '5' ORDER BY phone");
if ($result) {
while ($row = mysql_fetch_assoc($result)) {
// Обработка строк...
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question