Query returning all restults in DB not just the one I want ?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
farley2k
Forum Newbie
Posts: 5
Joined: Thu Jan 15, 2009 1:30 pm

Query returning all restults in DB not just the one I want ?

Post by farley2k »

First I must admit I am using code written by the guy who had this job before me so I didn't write it. That said, when you run this code against his database it returns only one record (based on the ID variable passed from the previous page) but when I run the code against my database it returns all the records. Below is the code, can anyone tell me why this is returning everything rather than a specific item? Thanks

Code: Select all

<html>
<head>
<title>Adult weekly schedules</title>
<link rel="stylesheet" href="site.css" type="text/css"/>
</head>
<body>
<?php 
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/FX.php" );
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/server_data.php" );
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/Developer/FMErrors.php" );
 
$query = new FX ($serverIP, $webCompanionport, $DataType);
$query->SetDBUserPass ($dbUser, $dbPassword);
$query->SetDBData('Weekly.fp7', 'Weekly');
$query->AddDBParam ('KeyID', $_GET['ID']);
$query->FMSkipRecords($skipSize);
 
 
$result = $query->FMFind();
$currentKey = key($result['data']);
$today= date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")));
$currenttime = date("h:i:s A");
/* print_r($result); */
 
if ($result['foundCount'] > 0) {
       foreach ($result['data'] as $key => $value) {
       $date = strtotime($value['Date'][0]);    // Converts FM date field to UNIX date
       $dateDisplay = date("l, F jS", $date);
       /* print_r($value['KeyID'][0]); */
       echo "<p><strong>Adult weekly schedules</strong> for the week of: <strong>" . $dateDisplay . "</strong><br />\n";
       echo "This schedule is up-to-date as of: " . $currenttime . "</p>\n"; 
       echo "<table width=640 cellpadding=1 cellspacing=0 border=0 bgcolor=#ffffff>\n";
       echo "<tr>\n";
       echo "<td width=75 bgcolor=#A5BFAA>" . $value[Sun01][0] . "</td>\n";
       echo "</tr>\n"; 
       }
       }
 
?>
 
</body>
</html>
 
 
 
 
farley2k
Forum Newbie
Posts: 5
Joined: Thu Jan 15, 2009 1:30 pm

Re: Query returning all restults in DB not just the one I want ?

Post by farley2k »

Just in case it helps here is the code from the previous page where the "ID" field is passed forward

Code: Select all

<html>
<head>
 
<link rel="stylesheet" href="site.css" type="text/css"/>
</head>
<body>
<table cellpadding=0 cellspacing=6 border=0 align=center>
<tr>
<td valign=top>
<?php 
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/FX.php" );
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/server_data.php" );
include_once($_SERVER['DOCUMENT_ROOT'] . "/FX/Developer/FMErrors.php" );
 
$query = new FX ($serverIP, $webCompanionport, $DataType);
$query->SetDBPassword ($dbPassword, $dbUser);
$query->SetDBData('Weekly.fp7', 'weekly', "All"); 
$query->AddSortParam('Date');
$query->FMSkipRecords($skipSize);
 
$result = $query->FMFindAll();
/* print_r($result); */
$currentKey = key($result['data']);
$rowcolor1 = '#ffffff';
$rowcolor2 = '#F2EABC';
$n = 0;
$today= date("Ymd",mktime(date("H"),date("i"),date("s"),date("m"),date("d"),date("Y")));
echo "<strong>Adult weekly schedules</strong></p>\n";
echo "<table cellpadding=1 cellspacing=0 border=0>\n";
echo "<tr>\n";
echo "<td class=green width=180><strong>Schedule for the week of:</strong></td>\n";
echo "</tr>\n";
if ($result['foundCount'] > 0) {
       foreach ($result['data'] as $key => $value) {
       $date = strtotime($value['Date'][0]);    // Converts FM date field to UNIX date
       $dateDisplay = date("l, F jS", $date);
       $eventdate = date("Ymd", $date);
       $difference = $eventdate - $today;
       $recID = $value['KeyID'][0];
       
       //The first comparision factors in the date change from the end of one month to the start of a new month
       if (($difference >= -76) || ($eventdate >= $today)){  
       
       if ($n % 2 == 1) {
       $style = $rowcolor2;
       }
       else {
       $style = $rowcolor1;
       }
       
       echo "<tr>\n";
       echo "<td bgcolor=" . $style . ">";
       echo "<a href=\"test2.php?id=$recID\">". $dateDisplay ."</a><br />\n";
       echo "</td>\n";
       echo "</tr>\n";
       $n++;
       }
       }
       }
 
       echo "</table>\n"; 
?>
</td>
</tr>
</table>
</body>
</html>
Post Reply