Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

associating one id with one or more files

Status
Not open for further replies.

samflex

IS-IT--Management
Jun 28, 2004
45
US
$sLastSiteCode = '';

//loop through, echoing the rows ...

if ($sLastSiteCode == $row['site_code'])
{
$row['site_code'] = ' ';
}
else
{
// End the table and print new headers
}
$sLastSiteCode = $row['site_code'];
// Print the row details as normal.
<?php
$conn = odbc_connect("counts", "", "") or die(odbc_error());
$sql = "SELECT
fctrafic.site_code,
fctrafic.location,
fctrafic.location2,
fctrafic.distance,
fctrafic.direction,
trafficcountsFiles.fdate,
trafficcountsFiles.types,
trafficcountsFiles.aadt,
trafficcountsFiles.filename
FROM trafficcountsFiles,fctrafic
WHERE fctrafic.site_code = trafficcountsFiles.sitecode
AND fctrafic.site_code = '".$_GET["site_Code"]."'";

$results = odbc_exec($conn,$sql);

for($count=0; $row = odbc_fetch_array($results); $count++)
{
?>
<html>
<head>
<title>Trafic Counts</title>
<link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body bgcolor="#6270B5">
<div align="center">
<table cellpadding="2" cellspacing="2">
<tr>
<td class="header"><font size="-3">SITE CODE</font></td>
<td class="name"><font size="-3"><?=$row["site_code"]?></font></td>
<td class="header"><font size="-3"> TYPE</font></td>
<td class="name"><font size="-3"><?=$row["types"]?></font></td>
</tr>
<tr>
<td class="header"><font size="-3">AADT</font></td>
<td class="name"><font size="-3"><?=$row["aadt"]?></font></td>
<td class="header"><font size="-3">DATE</font></td>
<td class="name"><font size="-3"><?=$row["fdate"]?></font></td>
</tr>
<tr>
<td class="header"><font size="-3">LOCATION</font></td>
<td class="name"><font size="-3"><?=$row["location"]?></font></td>
<td class="header"><font size="-3">DISTANCE</font></td>
<td class="name"><font size="-3"><?=$row["distance"]?></font></td>
</tr>
<tr>
<td class="header"><font size="-3">REF LOCATION</font></td>
<td class="name"><font size="-3"><?=$row["location2"]?></font></td>
<td class="header"><font size="-3">DIRECTION</font></td>
<td class="name"><font size="-3"><?=$row["direction"]?></font></td>
</tr>
<tr>
<td class="header"><font size="-3">FILE NAME</font></td>
<td class="name"><font size="-3"><a href='["site_code"]?>'><?=$row["filename"]?></a></font></td>
</tr>
</table>

<br>
<button name="close" value="Close" onClick="window.close()">Close</button>
</div>
<?
}

?>
</body>
</html>



I got great help in getting the above code to work.

The only problem that I have right now is to change the way data is displayed.

For instance, since more than one file can be associated with one site code, I will like to see the data display like this:

We would prefer one site code with all files together like below:

SITE CODE 31700020401 TYPE Volume
AADT NA DATE 5/20/2002
LOCATION Northside Drive DISTANCE
REF LOCATION Old Powers Ferry Road DIRECTION E
FILE NAME Riverview Rd EB 5-02.pdf
Northside Dr NB 5-02.pdf
Old Powers Ferry Rd WB 5-02.pdf
Northside Dr SB 5-02.pdf

Currently, it displays like below (which I would like to change to look like above:

SITE CODE 31700020401 TYPE Volume
AADT NA DATE 5/20/2002
LOCATION Northside Drive DISTANCE 1
REF LOCATION Old Powers Ferry Road DIRECTION S
FILE NAME Riverview Rd EB 5-02.pdf
Close

SITE CODE 31700020401 TYPE Volume
AADT NA DATE 5/20/2002
LOCATION Northside Drive DISTANCE
REF LOCATION Old Powers Ferry Road DIRECTION N
FILE NAME Northside Dr NB 5-02.pdf
Close

SITE CODE 31700020401 TYPE Volume
AADT NA DATE 5/20/2002
LOCATION Northside Drive DISTANCE
REF LOCATION Old Powers Ferry Road DIRECTION S
FILE NAME Northside Dr SB 5-02.pdf
Close

SITE CODE 31700020401 TYPE Volume
AADT NA DATE 5/20/2002
LOCATION Northside Drive DISTANCE
REF LOCATION Old Powers Ferry Road DIRECTION E
FILE NAME Old Powers Ferry Rd WB 5-02.pdf
Close

If you look at the above, you can see that the same site code is displayed 4 different types because it is associated with 4 different filenames.

Any help would be greatly appreciated.
 
try using group by or distinct in your query (whichever suits you best)
 
You're probably going to have to provide the additional logic in your PHP code.

Two loops, one which pulls the ID from the first table and a nested one which pulls all filenames matching that ID from the second table.

Conversely, you could just use the single query and teach your PHP script to know how to recognize when an ID changes.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top