Forum Moderators: coopster

Message Too Old, No Replies

selecting which field to display in array

         

Shaman13

4:00 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



I know its probably really simple but I am stumped. I am pulling a query from two tables which have some common fields. For example the field SNUM exists in both my tables. My problem is that my array is displaying values for that field taken from the wrong table. How do I specify which table to pull the field from in my array. Do I modify the query or the display of my array? Finally how should I alter the code below? I want to display the field SNUM from the ttime table instead of the table _clientsw_cases.

Thanks in advance for any insight!
////////////////////////////////////////////

$result = mysql_query( "SELECT * FROM ttime left join _clientsw_cases ON ttime.CASENUM=_clientsw_cases.CASENUM WHERE ttime.CASENUM='{$_GET['CASENUM']}' ORDER BY TIDATE ASC")
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "You currently have $num_rows time entries for case number "

?>

<font color="#FF0000"size="3">
<? echo $_GET['CASENUM']?><P>
</font>
</blockquote>
<center>
<font face="Times New Roman" size="3">
<?php
print("<TABLE BORDER=1,width=725,body bgcolor=#FFFFFF><TR>");
print("<TH>Time Date</TH>");
print("<TH>Time Spent</TH>");
print("<TH>Reason</TH>");
print("<TH>Time Activity</TH>");
print("<TH>Case Activity</TH>");
print("<TH>Advocate</TH>");
print("<TH>Funds</TH>");
print("<TH>Add Time</TH>");
print("<TH>Edit Time</TH>");
for ($index = 0; $index < 5; $index++)

while($row=mysql_fetch_array($result)) {

print '<tr><td>'.$row['TIDATE'].'</td><td>'.$row['TTIME']. '</td><td>'.$row['REASON'].'</td><td>'.$row['TIMEACTIVITY']. '</td><td>'.$row['CASEACTIVITY'].'</td><td>'.$row['SNUM']. '</td><td>'.$row['FUNDSNUM'].'</td>
<TD><a href="T12.php? CASENUM='.$row['CASENUM'].'">Add Time</a></td><TD><a href="time_edit.php? TIMEID='.$row['TIMEID'].'">Edit Time</a></td></tr>';
}
$_SESSION['CASENUM']=$_GET['CASENUM'];

?>

[edited by: jatar_k at 5:05 pm (utc) on Dec. 14, 2004]
[edit reason] fixed sidescroll [/edit]

Salsa

5:00 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



You might have to use aliases. Instead of using the wild card, SELECT *, do something like this to specify exactly which fields you want to select and how to rename them for reference:

SELECT ttime.SNUM AS ttime_SNUM, ...

...and later you'll get the correct data with

$row['ttime_SNUM']

I hope this helps.

Shaman13

5:42 pm on Dec 14, 2004 (gmt 0)

10+ Year Member



Perfect Salsa! That worked excellent! Thanks!