Jump to content

Recommended Posts

Hi All

 

basically, I have a select that draws the desired results.

 

Within these results I then need to produce a number for if the case is closed.

 

The field value is 'case_open'

 

so if the case open is set to yes, the number of rows that say yes in that particular field and the same for no

 

can anyone give me any direction for this please?

  • 2 weeks later...

thanks greensmurf, but thats not what im after

 

basically, trying to create a results page from a form and need two things that am really stuck on.

 

1. If the form value ="" then i need it to return all the results in that table field.

2. I need to then take those results and count certain values. For example, how many case_open fields have the "yes" value and then return that value as a number

 

Code for part 1.

$ethnic = $_REQUEST['ethnic'];
$gender = $_REQUEST['gender'];
$referral = $_REQUEST['referral'];
$age = $_REQUEST['age'];
$month = $_REQUEST['month'];
$year = $_REQUEST['year'];

$query  = "SELECT * from tbl WHERE";

if ((!empty($_POST['ethnic']))&&($_POST['ethnic'] != 'all')) { $query .= " ethnic_background like '". addslashes($_POST['ethnic'])."%' "; }

if ((!empty($_POST['gender']))&&($_POST['gender'] != 'all')) { $query .= " and gender like '". addslashes($_POST['gender'])."%' "; }


if ((!empty($_POST['age']))&&($_POST['age'] != 'all')) { $query .= " and age_range like '". addslashes($_POST['age'])."%' "; }

if ((!empty($_POST['month']))&&($_POST['month'] != 'all')) { $query .= " and date_received_month like '". addslashes($_POST['year'])."%' "; }

if ((!empty($_POST['year']))&&($_POST['year'] != 'all')) { $query .= " and date_received_year like '". addslashes($_POST['year'])."%' "; }

$result = mysql_query($query);
$numrows=mysql_num_rows($result);
if ($numrows == 0)
  {

  echo "<div class=\"heading\">Sorry, your search returned no results. Please go back and try again!</div>";

  }

 

I then run a loop i.e.

 <? while ($row = mysql_fetch_assoc($result)) {

?>

 

Then i need to return the results below in a table i.e.

<table><tr>
                <td valign="top" height="30" style="border-bottom:1px #ccc solid;" class="bodytext_table"><div align="left"> Number of IMHA cases opened</div></td>
	<td style="border-bottom:1px #ccc solid;"> <div align="right" style="color:#993366; font-size:12px; font-weight:600;">number here</div></td> </tr></table>

 

can someone shed some light please, its really urgent and need it tonight and have searched high and low for answers!!!

 

any help appreciated!

 

thanks

The SELECT SUM will work if you want to make another trip to the database.  However why not just count them while you are outputting them to the table?

 

$open_count = 0
while ($row = mysql_fetch_assoc($result)) {
   if ($row['case_open'] == 'yes') $open_count++;
}

 

 

right, I guess I should actually RTFP.  I thought OP was listing all the data to the page in the loop and wanted to add the count at the end.  If there is no need to list the data, then the SELECT SUM is definitely the way to go.  Uses less resources all the way around.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.