zebmckey
24-04-2018, 09:22
Buongiorno, non riesco ad associare ad un ID una data e ripetere la sequenza fino alla fine delle date.
esempio:
id data
1 01/01/18
2 02/01/18
3 03/01/18
l'ID viene ricavato da una query su una tabella SQL invece le date le ricavo direttamente da php.
<?php
session_start ();
require_once '../conf/conf.php';
$con = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
date_default_timezone_set('Europe/Rome');
$startdate=strtotime("Saturday");
$enddate=strtotime("+6 month", $startdate);
while ($startdate < $enddate)
{
?>
<table>
<tr>
<th>ID</th>
<th>DATA</th>
</tr>
<?php
$data = "SELECT `idpersinsp` FROM `utenze`.`persg`;";
$result = mysqli_query($con,$data);
if(!$result)
{
die("Database query failed: " . mysqli_error());
}
while ($row = mysqli_fetch_array($result))
{
$id=$row["idpersinsp"];
?>
<tr>
<td><?php echo $id;?></td>
<?php
}
?>
<td><?php echo date("M d Y", $startdate); ?></td></tr></table>
<?php
$startdate = strtotime("+1 week", $startdate);
}
mysqli_close($con);
?>
ma cosi facendo ho una lista di ID e le date si associano solo all'ultimo ID. Come posso fare per far in modo che ad ogni id corrisponda una sola data?
Grazie
esempio:
id data
1 01/01/18
2 02/01/18
3 03/01/18
l'ID viene ricavato da una query su una tabella SQL invece le date le ricavo direttamente da php.
<?php
session_start ();
require_once '../conf/conf.php';
$con = new MySQLi(DB_HOST, DB_USER, DB_PASS, DB_NAME);
date_default_timezone_set('Europe/Rome');
$startdate=strtotime("Saturday");
$enddate=strtotime("+6 month", $startdate);
while ($startdate < $enddate)
{
?>
<table>
<tr>
<th>ID</th>
<th>DATA</th>
</tr>
<?php
$data = "SELECT `idpersinsp` FROM `utenze`.`persg`;";
$result = mysqli_query($con,$data);
if(!$result)
{
die("Database query failed: " . mysqli_error());
}
while ($row = mysqli_fetch_array($result))
{
$id=$row["idpersinsp"];
?>
<tr>
<td><?php echo $id;?></td>
<?php
}
?>
<td><?php echo date("M d Y", $startdate); ?></td></tr></table>
<?php
$startdate = strtotime("+1 week", $startdate);
}
mysqli_close($con);
?>
ma cosi facendo ho una lista di ID e le date si associano solo all'ultimo ID. Come posso fare per far in modo che ad ogni id corrisponda una sola data?
Grazie