CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 sql count question [resolved]

Print topic Send  topic

Author Message
kirchaj

Posts: 215
Posted: 05/28/2009, 11:22 AM

Hey all,

Tired of banging my head against the wall on this one.

I have an image I want to make visible if the record count of a related table is >0. I have tested my sql and it works properly, but I only get a 1 from this code even if the result is actually 0. I put this in the beforeshowrow event

$db = new clsDBportfolio();
$countsql="SELECT count (*) FROM student_scores WHERE student_scores.stu_id=".CCGetUserID()." AND course_cp_index=".$course_cp_course_semester->course_cp_index->GetValue().
" AND crssem_index=".$course_cp_course_semester->crssem_index->GetValue().";";

// echo $countsql;
$scorecount = $db->query($countsql);
// echo $scorecount;
$result = $db->next_record();
// echo $result;

if ($result == 0) {
$course_cp_course_semester->scoresavailable->Visible = 0; }

$db->close();

I may be going about this the wrong way but it seemed like an easy idea when I started. Any ideas would be greatly appreciated.

TK
View profile  Send private message
lvalverdeb

Posts: 299
Posted: 05/28/2009, 11:36 AM

Try:
  
$db = new clsDBportfolio();  
$where = "student_scores.stu_id=".CCGetUserID() ." AND course_cp_index=".$course_cp_course_semester->course_cp_index->GetValue().  
" AND crssem_index=".$course_cp_course_semester->crssem_index->GetValue();  
$result = CCDLookUp("count(*)", "students_scores",$where, $db);  
$course_cp_course_semester->scoresavailable->Visible = $result;  

FYI, the reason you're getting 1 in result is because $db->next_record is returning true because the recordset is not null. For your code to work you'd need to change it as follows:

  
$db = new clsDBportfolio();  
$countsql="SELECT count (*) FROM student_scores WHERE student_scores.stu_id=".CCGetUserID()." AND course_cp_index=".$course_cp_course_semester->course_cp_index->GetValue().  
" AND crssem_index=".$course_cp_course_semester->crssem_index->GetValue().";";  
  
// echo $countsql;  
$scorecount = $db->query($countsql);  
// echo $scorecount;  
$result = $db->next_record();  
if ($result) {  
    $result = $db->f(0); // the value in the first field of the recordset.  
}  
// echo $result;  
  
if ($result == 0) {  
$course_cp_course_semester->scoresavailable->Visible = 0; }  
  
$db->close();  

_________________
lvalverdeb
CR, GMT-6
XAMPP/Ubuntu/CCS3.2/4
View profile  Send private message
kirchaj

Posts: 215
Posted: 05/28/2009, 1:13 PM

lvalverdeb,

You were right on the money. Couple of minor tweaks and it works like a champ.

I knew why I was getting the wrong answer, I just didn't know how to fix it :)

Thanks for your help.

TK
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.