I've been trying to work out a problem but I'm having no luck. I have
field in my table for area and I need to count the number of matches
and assign a variable for each one.. this is what I have but it doesn't
work.. any ideas?
$testcount = mysql_query("se lect area, count(area) as newcount from rea
group by area order by area");
while ($returncount = mysql_fetch_arr ay($testcount)) {
if ($returncount[area] == 'RCC') {
$rccn = $returncount[newcount];
}
if ($returncount[area] == 'RCL') {
$rccl = $returncount[newcount];
}
if ($returncount[area] == 'RCH') {
$rcch = $returncount[newcount];
}
if ($returncount[area] == 'RCW') {
$rccw = $returncount[newcount];
}
if ($returncount[area] == 'RNK') {
$rnkn = $returncount[newcount];
}
if ($returncount[area] == 'RNK') {
$rnen = $returncount[newcount];
}
} 6 1571
On 20 Jun 2005 11:39:15 -0700, "Bryan" <br********@gma il.com> wrote: I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have but it doesn't work.. any ideas?
*sigh* In what way does it not work?
What did you expect it to do?
What does it do?
How do the two differ?
Saying "it doesn't work" without explaining what it does do is not helpful and
could result in getting replies that are even more irritable than this one ;-)
$testcount = mysql_query("se lect area, count(area) as newcount from rea group by area order by area");
You haven't checked whether this query worked or not.
Check the return value. If it is false, then the query has failed. The error
is available from mysql_error().
It will also show a warning message, unless you have PHP configured to not
show or log warnings.
You must develop code with errors enabled (see the display_errors and
error_reporting options), and preferably warnings set to maximum, else you are
coding blindfolded.
One thing that jumps out is whether the table really called 'rea'? Or did you
mean 'area'?
With error checking and errors displayed, PHP would have told you this, and
you'd be certain about what's wrong - instead you're posting to thousands of
people asking them to guess based on insufficient information.
while ($returncount = mysql_fetch_arr ay($testcount)) { if ($returncount[area] == 'RCC') {
Associative array keys should be quoted else it'll raise a warning. It
wouldn't stop the code working, though (unless you had a constant named
'area').
$rccn = $returncount[newcount]; } if ($returncount[area] == 'RCL') { $rccl = $returncount[newcount]; } if ($returncount[area] == 'RCH') { $rcch = $returncount[newcount]; } if ($returncount[area] == 'RCW') { $rccw = $returncount[newcount]; } if ($returncount[area] == 'RNK') { $rnkn = $returncount[newcount]; } if ($returncount[area] == 'RNK') { $rnen = $returncount[newcount]; } }
OK, so how do you know it didn't work?
You need to post an example of the input data and the output data to prove it
didn't work.
--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
On Mon, 20 Jun 2005 11:39:15 -0700, Bryan wrote: I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have but it doesn't work.. any ideas?
$testcount = mysql_query("se lect area, count(area) as newcount from rea group by area order by area"); while ($returncount = mysql_fetch_arr ay($testcount)) { if ($returncount[area] == 'RCC') { $rccn = $returncount[newcount]; } if ($returncount[area] == 'RCL') { $rccl = $returncount[newcount]; } if ($returncount[area] == 'RCH') { $rcch = $returncount[newcount]; } if ($returncount[area] == 'RCW') { $rccw = $returncount[newcount]; } if ($returncount[area] == 'RNK') { $rnkn = $returncount[newcount]; } if ($returncount[area] == 'RNK') { $rnen = $returncount[newcount]; } }
Like Andy said, try some basic error checking first
// always initialise variables before you use them
$aAreas = array();
$sql = "select area, count(area) as newcount from rea group by area order
by area";
$results = mysql_query($sq l , $conn); if(! $results || mysql_error($co nn)
|| mysql_num_rows( $results)<1) {
echo "Unable to get results [$sql] : " . mysql_error($co nn);
}
else
{
// why use 10 variables when 1 will do?
while($row = mysql_fetch_arr ay($results)) {
$aAreas[$row[area]] = $row[newcount];
}
// $aAreas will now hold your results with the extra
print_r($aAreas ) . "<br>\n";
}
Bryan wrote: I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have but it doesn't work.. any ideas?
$testcount = mysql_query("se lect area, count(area) as newcount from rea group by area order by area");
MySql queries involving count(columname ) require a GROUP BY clause, for
starters.
WMD
On Mon, 20 Jun 2005 21:06:21 GMT, Wayne Delia <wm*@deliafamil y.net> wrote: Bryan wrote: I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have but it doesn't work.. any ideas?
$testcount = mysql_query("se lect area, count(area) as newcount from rea group by area order by area");
^^^^^^^^^^^^^ MySql queries involving count(columname ) require a GROUP BY clause, for starters.
Like the one he's already got? :-)
--
Andy Hassall / <an**@andyh.co. uk> / <http://www.andyh.co.uk >
<http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool
Andy Hassall wrote: On Mon, 20 Jun 2005 21:06:21 GMT, Wayne Delia <wm*@deliafamil y.net> wrote:
Bryan wrote:
I've been trying to work out a problem but I'm having no luck. I have field in my table for area and I need to count the number of matches and assign a variable for each one.. this is what I have but it doesn't work.. any ideas?
$testcount = mysql_query("se lect area, count(area) as newcount from rea group by area order by area");
^^^^^^^^^^^^^
MySql queries involving count(columname ) require a GROUP BY clause, for starters.
Like the one he's already got? :-)
Oh, man - I can't believe that. That's about the third similar mistake
I've made today. I should probably go back to bed right now.
WMD
Thanks for replying -- Please excuse my ignorance. I come from the
world of Excel and I'm having a little difficulty grasping the full
concept of PHP/MySQL.
The first variable (RCC) works fine, it returns "2" which it should.
The second variable (RCL) also returns "2" but should return "26".
The rest of the variables return nothing although most of them have
should have values (and some of the areas haven't yet been entered into
the table). I will try some other troubleshooting suggestions from CJ. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Kong Li |
last post by:
Follow up to this thread, the latest Oracle 9i release 2 patchset
(9.2.0.5) fixed the handle count leak problem. The problem is in
Oracle client component.
Thanks.
Kong
-----
From: Kong Li (likong@email.com)
|
by: rob.guitar.rob |
last post by:
Hello,
My last few posts have been revolving aroung the same problem, and I
still cant solve it and I would be really appreciate if anyone could
spot a problem.
a section of my XML goes like
.....
<parent>
|
by: Irfan |
last post by:
Hello,
I am having some problem with count function.
I have a report in which has grouping by a person wise and sub grouping in
invoied status e.g.. the output will be
Irfan Records (First Grouping by Person Wise)
Total Number of Records = 30 (I am using count("*") funtion to get this and
|
by: Invalidlastname |
last post by:
Hi,
We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
|
by: novus |
last post by:
Hi,
In ASP.net 2.0 I make a control which add the same controls dynamically. In
the oninit event I add the controls to the controls collection. After that
the loadviewstate event fills in the information on postbacks. The control
can add and delete controls that is why on the postback I don't know how many
controls there are.
At the moment I am able to get the controls rendering but I have problems to
save the count of the dynamic...
| |
by: Martin Joergensen |
last post by:
Hi,
I have some files which has the following content:
0 0 0 0 0 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 1 1 1 1 0
0 0 0 0 0 0
|
by: Igor |
last post by:
I have one SELECT statement that needs to return one ntext field from
one table and count something from other table, problem is that all
fileds that are not in count have to be in group by and ntext can't be
in group by... i hope you understend what i want to say here :), so is
there any solution to this problem or what is the best workaraund you
would use?
example:
TABLE projects
project_id int
|
by: Gary Wessle |
last post by:
Hi
I have a vector<charwhich looks like this (a d d d a d s g e d d d d
d k)
I need to get the biggest count of consecutive 'd'. 5 in this example
I am toying with this method but not sure if it is optimal.
thanks
int k = 0;
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source=" & msDbFilename
moConn.Properties("Persist Security Info") = False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite' or using default...same result
|
by: haresh.amis |
last post by:
hello to all,
I m using .net 2.0 and i face a problem that is as under
Well I have a checkboxlist which i bound in .cs page
now I want to count that how many checkboxes ate checked ( In
javascript ) and
checked checkboxes text will be concat and that string will be pass on
to report query
I m trying on by this code but it's not work
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |