gpt4 book ai didi

php - 将唯一标识符添加到 PHP for 循环中的第一次迭代

转载 作者:行者123 更新时间:2023-11-30 00:54:12 25 4
gpt4 key购买 nike

我在客户的网站上使用 for 循环将购买的门票信息插入数据库。循环工作正常,但客户端请求在每次运行 for 循环时将唯一标识符附加到第一个条目的选项。该标识符将用于在打印门票时突出显示主要门票所有者。我在下面包含了当前的 for 循环以供引用。关于如何实现这一目标有什么想法吗?谢谢。

$threepack = '';
$i = '';
for($i = 0; $i < $tickets; $i++)
{
$firstname = 'firstname'.$threepack;
$lastname = 'lastname'.$threepack;
$address = 'address'.$threepack;
$city = 'city'.$threepack;
$postal = 'postal'.$threepack;
$phone = 'phone'.$threepack;
$altphone = 'altphone'.$threepack;
$sec_firstname = 'sec_firstname'.$threepack;
$sec_lastname = 'sec_lastname'.$threepack;
$email = 'email'.$threepack;

$table->firstname = $data->$firstname;
$table->lastname = $data->$lastname;
$table->address = $data->$address;
$table->city = $data->$city;
$table->postal = $data->$postal;
$table->phone = $data->$phone;
$table->altphone = $data->$altphone;
$table->sec_firstname = $data->$sec_firstname;
$table->sec_lastname = $data->$sec_lastname;
$table->email = $data->$email;
$table->id = 0;
$table->order_total = $data->total;
$table->store();

if($data->tickets == '-1')
{
if($threepack == 2)
{
$threepack = 3;
} else {
$threepack = 2;
}
}

// 8 Fields
if($data->tickets == '5')
{
if ($threepack == '') {
$threepack = 2;
} else {
$threepack += 1;
}
}
}

最佳答案

for ($i = 0; $i < $tickets; $i++) {
// ...

if ($i == 0)
$table->highlightme = 1;
// ...

$table->store();

// ...
}

关于php - 将唯一标识符添加到 PHP for 循环中的第一次迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20725497/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com