Page 1 of 1

Help with MySQL Query inside a MySQL Query please

Posted: Thu Apr 12, 2007 7:29 am
by ianhull
Here is what I have,

Unfortunatley it only returns one record for the users but there is more available.

Can anyone see why it is only returning 1 record?

Code: Select all


<?php session_start(); 

$calday = $_GET['calday']; 
$calmonth = $_GET['calmonth']; 
$calyear = $_GET['calyear']; 
$location = $_SESSION['user']['location']; 

include_once("../_includes/connection.php"); 

$getUsers = mysql_query("SELECT 
id, 
firstname, 
lastname, 
location, 
level FROM users where level = 'User' AND location = '$location'")or die(mysql_error());  

$name = array(); 
while ($usersRecieved = mysql_fetch_array($getUsers))    
{ 
extract($usersRecieved); 
$name[] = $firstname . ' ' . $lastname; 
} 
foreach( $name as $value){ 
        echo "$value <br />"; 
                
$checkCalendarDay = mysql_query("SELECT 
id, 
name, 
company_name, 
appointment_time, 
appointment_day, 
appointment_month, 
appointment_year, 
city_town, 
location, 
postcode_1, 
postcode_2 FROM currentappointments WHERE name = '$value' AND appointment_day = '$calday' AND appointment_month = '$calmonth' AND appointment_year = '$calyear' AND location = '$location' ORDER BY name")or die(mysql_error()); 

if(mysql_affected_rows() == 0){ 
echo 'There is no apointments listed for '.  $_SESSION['user']['location'] .  ' ' . $_GET['calday'] . ' ' . $_GET['calmonth'] . ' ' . $_GET['calyear'] . '<br /><br /><a href="add_appointment_set.php?d='.$calday.'&m='.$calmonth.'&y='.$calyear.'">Click here to add a new appointment</a>'; 
exit(); 
}; 
} 
echo '<center><h3>' . $calday . '/' . $calmonth . '/' . $calyear . '</h3></center>'; 
while ($calendarChecked = mysql_fetch_array($checkCalendarDay))    
{ 
extract($calendarChecked); 
echo ' 
<table width="99%" border="0" cellpadding="3" cellspacing="3" onClick="document.location.href=\'add_appointment.php?rep='.$name.'\';" onMouseOver="this.bgColor=\'#F3F8FC\';" onMouseOut="this.bgColor=\'#FFFFFF\';" class="grey-body"> 
  <tr> 
    <td>'.$appointment_time.' - '.$city_town.' - '.$location.' - '.$postcode_1.' - '.$company_name.'</td> 
  </tr> 
</table>'; 
} 
?> 
Thanks

Posted: Thu Apr 12, 2007 7:32 am
by feyd
Shouldn't this have been in your previous thread about this code?

Your foreach iterates over the names producing queries, but the code to display the result set from that isn't inside the foreach, but after it.

Proper indentation should have told you this, really.