I got this in my SQL while loop:
PartID:1 Year:2003 ModelID:1375
PartID:1 Year:2004 ModelID:1375
PartID:1 Year:2005 ModelID:1375
PartID:2 Year:1995 ModelID:1244
PartID:2 Year:1996 ModelID:1244
PartID:2 Year:1997 ModelID:1244
PartID:2 Year:1998 ModelID:1244
PartID:2 Year:1999 ModelID:1244
PartID:2 Year:2000 ModelID:1244
PartID:2 Year:2001 ModelID:1244
PartID:2 Year:1996 ModelID:2361
PartID:2 Year:1997 ModelID:2361
PartID:2 Year:1998 ModelID:2361
PartID:2 Year:1999 ModelID:2361
PartID:2 Year:2000 ModelID:2361
But I need it like this for database insert (PartId, Start_Year, End_Year, ModelId):
PartID:1 Start Year:2003 End year:2005 ModelID:1375
PartID:2 Start Year:1995 End year:2001 ModelID:1244
PartID:2 Start Year:1996 End year:2000 ModelID:2361
Do you have any idea how to do that in SQL While Loop or in SQL query. These are tables:
model2year
id | model_id | year
1 1 1966
2 2 1973
3 2 1972
4 2 1971
5 2 1970
model2year2part
id | model2year_id | part_id
1 9521 1
2 9520 1
3 9519 1
4 8637 2
5 8636 2
These are example tables:
http://milversite.net/model2year.zip
http://milversite.net/model2year2part.zip
This is sql query for tables above
$result = mysql_query("SELECT * FROM model2year JOIN model2year2part ON model2year2part.model2year_id = model2year.id");
while($row = mysql_fetch_array($result))
{
$part_id = $row['part_id'];
$year = $row['year'];
$model_id = $row['model_id'];
echo "PartID:$part_id Year:$year ModelID:$model_id<br>";
}
but I need to insert that in this result table without duplicated model_id and instead of that with years range from min. to max for model_id:
result_table
part_id | model_id | start_year | end_year
Thank you!
{ }) on the editor toolbar to nicely format and syntax highlight it! That way, you don't need a flood of messy<br>and tags, either!!