Forum Moderators: coopster
$query ="SELECT * FROM service ORDER BY date_booked DESC";
$result = mysql_query($query);
if (!$result)
die(mysql_error());
while ($r = mysql_fetch_array($result)) {
extract($r);
$tech_name=mysql_result($result,$i,"tech_name");
$user_id2=mysql_result($result,$i,"user_id");
$fault=mysql_result($result,$i,"fault");
$resolution=mysql_result($result,$i,"resolution");
$charge=mysql_result($result,$i,"charge");
$status=mysql_result($result,$i,"status");
$note=mysql_result($result,$i,"note");
$date_complete=mysql_result($result,$i,"date_complete");
?>
<?php
require_once ('mysql_connect.php');
$query2 ="SELECT * FROM users WHERE user_id='$user_id2'";
$result2 = mysql_query($query2);
$user_id=mysql_result($result2,$i,"user_id");
$first_name=mysql_result($result2,$i,"first_name");
$last_name=mysql_result($result2,$i,"last_name");
$phone=mysql_result($result2,$i,"phone");
$mobile=mysql_result($result2,$i,"mobile");
$note=mysql_result($result2,$i,"note");
$email=mysql_result($result2,$i,"email");
?>
===============
So far my query Works for only the first results, displaying both the users first/last name, and the details corresponding to him, but it does not work for any of the other results. I recieve the error:
=======
Warning: Unable to jump to row 1 on MySQL result index 4 in /home/stormweb/public_html/x14/view_service3.php on line 41
=======
If anyone has any ideas? or know what i am doing wrong. If any other information is needed please just ask. I appreciate your help! Thanks
Your while loop isn't closed.
$i is used, but never declared or incremented.
$i is used to access the elements of both queries.
There's no point requiring once the same file twice.
Have you thought of a join? E.G.
SELECT s.*,u.* FROM service s INNER JOIN users u on u.user_id=s.user_id ORDER BY s.date_booked DESC
That should get all of the information in a single query. HOWEVER, watch out for extract if columns in the two tables have the same name.
$query ="SELECT s.*,u.* FROM service s INNER JOIN users u on u.user_id=s.user_id ORDER BY s.date_booked DESC ";
$result = mysql_query($query);
if (!$result)
die(mysql_error());
while ($r = mysql_fetch_array($result)) {
extract($r);
$tech_name=mysql_result($result,$i,"tech_name");
$date_booked=mysql_result($result,$i,"date_booked");
$status=mysql_result($result,$i,"status");
$note=mysql_result($result,$i,"note");
$first_name=mysql_result($result,$i,"first_name");
$last_name=mysql_result($result,$i,"last_name");
?>
<span class="style3">
<tr>
<td><font face="Arial" size="1"><b><?php echo $date_booked;?></b></font></td>
<td><font face="Arial" size="1"><?php echo $last_name.", ".$first_name;?></font></td>
<td><font face="Arial" size="1"><?php echo $tech_name;?></font></td>
<td><font face="Arial" size="1"><?php echo $status;?></font></td>
<td><font face="Arial" size="1"><a href="more.php?id=<?php echo $user_id;?>">View Member</a> </font></td>
<td><font face="Arial" size="1"><a href="more_service.php?id=<?php echo $service_id;?>">View Report</a> </font></td>
<td><font face="Arial" size="1"><a href="print_service.php?id=<?php echo $service_id;?>">Print Report</a> ¦</font></td>
<td><font face="Arial" size="1"><a href="amend_service.php?id=<?php echo $service_id;?>">Edit Report</a></font></td>
</tr>
</span>
<?php
$i++;
}
echo "</table>";
?>
======