I want to create an array with no repetitive element. I created an empty array at first, but it's meaningless to do that in PHP. A better way?
Table1:
Id Name
Table2:
Id Year PROJECT DURATION
1 2012 A 3
1 2012 B 2
Get data:
$sql = $mysqli->prepare(SELECT Name,
Table1.Id,
Year
FROM Table1 JOIN Table2
WHERE Table1.Id=Table2.Id
ORDER BY Id);
$sql->execute();
$result = $sql->get_result();
$Id[]=array();
while($row = $result->fetch_assoc()){
if (!in_array($row["Id"], $Id)){
$Id[]=$row["Id"];
...
}
}
I do not use DISTINCT because I need all year
, project
and duration
entries later. I could change the database. How to modify and use unique Id in table2? Thanks for the suggestions.