PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #16  
Old August 21st, 2008, 03:22 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
That doesn't show all the details linked with each name it just shows each name with each detail.

If there is a name 3 times in the database with 3 different types of details that are search for it should show the name with 3 different types of details under it and then the count should be 3, the order should start with the names that has most details.

Thanks for your help

Reply With Quote
  #17  
Old August 21st, 2008, 03:45 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
This mite make it easier details is the same as criteria

Reply With Quote
  #18  
Old August 21st, 2008, 05:08 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
I got it to show the right details under the name but I can't get the div to end on the last details so it looks messed up any1 got any ideas??

PHP Code:
if ($a1["Name"] != $fundn
        {
        
$fundn $a1["Name"];
          echo 
"<img src=\"Images/" . (($expanded[$n] == 0) ? "plus" "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\">  $a1[Name]";
          echo 
"<div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" "") . "\">";
        }
      echo 
$a1['Details'];
      if (
$a1["Name"] != $fundn
        {
            echo 
"</div>";
        } 

Reply With Quote
  #19  
Old August 21st, 2008, 05:13 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 400 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 8 sec
Reputation Power: 2
if ($a1["Name"] != $fundn) <--- This must be false.
__________________
Sir, a desire of knowledge is the natural feeling of mankind; and every human being, whose mind is not debauched, will be willing to give all that he has to get knowledge.

Reply With Quote
  #20  
Old August 21st, 2008, 05:17 PM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 400 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 8 sec
Reputation Power: 2
In fact on second glance you set $fundn = $a1["Name"]; so of course the if ($a1["Name"] != $fundn) statement would be false, you can't say:

If 'X' != 'Y' then set 'X'='Y' and then expect 'X' to not equal 'Y' after you just set it equal to 'Y'.

Reply With Quote
  #21  
Old August 21st, 2008, 06:05 PM
IAmALlama IAmALlama is online now
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,907 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 30 sec
Reputation Power: 4
PHP Code:
if ($a1["Name"] != $fundn)  
        { 
          echo 
"<img src=\"Images/" . (($expanded[$n] == 0) ? "plus" "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\">  $a1[Name]"
          echo 
"<div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" "") . "\">"
        } 
      echo 
$a1['Details']; 
      if (
$a1["Name"] != $fundn)  
        { 
            echo 
"</div>"
        }  
        
$fundn $a1["Name"]; 

just set $fundn at the end. It would be equal to whatever the last iteration was. If name is different from the last iteration, then you echo the div stuff.

Reply With Quote
  #22  
Old August 22nd, 2008, 04:35 AM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
Nope still don't work, heres the code so far:

PHP Code:
<?php
  $n 
0;
  
$count 0
   while(
$a1 mysql_fetch_array($r1))
    {    
      
$n++;
?>
  <tr>
    <td valign="top">
    <script language="JavaScript">
    expanded[<?php echo $n?>] = 0
    </script>
<?php
    
if ($a1["Name"] != $fundn
        {
        
$fundn $a1["Name"];
          echo 
"<img src=\"Images/" . (($expanded[$n] == 0) ? "plus" "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\">  $a1[Name]";
          echo 
"<div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" "") . "\">";
        
//reset the count.
        
$count 0
        }
          echo 
$a1['Criteria'];
           
//add 1 to the count.
            
$count++; 
        
        if (
$a1["Name"] != $fundnn)  
        { 
            echo 
"</div>"
        }  
        
$fundnn $a1["Name"]; 
    
?>    </td>
    <td align="center" valign="top"><?php echo $count?></td>
  </tr>
<?php
    
}
?>


The count works, but the div does not close in the right place it should close on the last echo $a1['Criteria']; for that "Name".

Is there a way to put it in order so the Name with the highest count is at the top?

Thanks

Last edited by drewj2k : August 22nd, 2008 at 04:48 AM.

Reply With Quote
  #23  
Old August 22nd, 2008, 07:57 AM
jamestrowbridge jamestrowbridge is offline
Contributing User
Click here for more information.
 
Join Date: Jul 2008
Location: Cleveland, Ohio, USA
Posts: 400 jamestrowbridge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 15 h 59 m 8 sec
Reputation Power: 2
Can you post the HTML source of this page? I think what you mean is:

$count = 0;
}
echo $a1['Criteria'];
echo "</div>";
//add 1 to the count.
$count++;

$fundnn = $a1["Name"];

Reply With Quote
  #24  
Old August 22nd, 2008, 09:58 AM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
Quote:
Originally Posted by jamestrowbridge
Can you post the HTML source of this page? I think what you mean is:

$count = 0;
}
echo $a1['Criteria'];
echo "</div>";
//add 1 to the count.
$count++;

$fundnn = $a1["Name"];


Because you could have for example 3 criteria s listed there if you closed the div on the first criteria the second 2 wouldn't appear in the correct place if that makes any sense?

Reply With Quote
  #25  
Old August 22nd, 2008, 12:52 PM
IAmALlama IAmALlama is online now
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,907 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 30 sec
Reputation Power: 4
and if you wanted to sort by the name with the most details, you would probably need to do a subquery to get a count of how many details are under each name and sort by that.

PHP Code:
 $q1 "SELECT *, (SELECT COUNT(*) FROM table AS t2 WHERE `Name`=`table`.`Name`) AS `count` FROM table WHERE (".$criteria.") ORDER BY `count`, `Name`, `Details`"

Then you can get rid of the $count variable and use the count from the query.

Reply With Quote
  #26  
Old August 22nd, 2008, 01:18 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
Thanks Ala but it does not order them by the count here is the query with my values:

PHP Code:
 $q1 "SELECT *, (SELECT COUNT(*) FROM TableName AS t2 WHERE `Name`=`TableName`.`Name`) AS `count` FROM TableName WHERE (".$criteria.") ORDER BY `count`, `Name`, `Criteria`"


Can you check it is correct?

Thanks

Reply With Quote
  #27  
Old August 22nd, 2008, 01:45 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
Also the count is showing weird numbers ?!

Here is all the code so far:

PHP Code:
<?php
$q1 
"SELECT *, (SELECT COUNT(*) FROM TableName AS t2 WHERE `Name`=`TableName`.`Name`) AS `count` FROM TableName WHERE (".$criteria.") ORDER BY `count`, `Name`, `Criteria`";  
  
  
$n 0;
  
$count 0
   while(
$a1 mysql_fetch_array($r1))
    {    
?>
  <tr>
    <td valign="top">
    <script language="JavaScript">
    expanded[<?php echo $n?>] = 0
    </script>
<?php
    
if ($a1["Name"] != $fundn
        {
        
$n++;
        
$fundn $a1["Name"];
          echo 
"<img src=\"Images/" . (($expanded[$n] == 0) ? "plus" "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\">  $a1[Name]";
          echo 
"<div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" "") . "\">";
          
//reset the count. 
        
}
           echo 
$a1['Criteria'];
           
        if (
$a1["Name"] != $fundcheck) {
            echo 
"</div>"
            echo 
'</td><td align="center" valign="top">';
            echo 
$a1['count'];
            echo 
"</td></tr>";
        }
        
        
$fundcheck $a1["Name"];
    }

Reply With Quote
  #28  
Old August 22nd, 2008, 01:54 PM
IAmALlama IAmALlama is online now
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,907 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 30 sec
Reputation Power: 4
oops, the count should be order desc.

ORDER BY `count` DESC, `Name` ASC, `Criteria` ASC

Reply With Quote
  #29  
Old August 22nd, 2008, 02:00 PM
drewj2k drewj2k is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Posts: 162 drewj2k User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 5 h 14 m 42 sec
Reputation Power: 3
Haha the order is correct now but the count is still wrong I have weird numbers like:

29
29
29
29
29
27
27
25
24

when it should be like

4
4
4
3
3
3
2
2

I don't understand the sub query but It needs to count the amount of Criterias to each Name.

Thanks

Last edited by drewj2k : August 22nd, 2008 at 02:03 PM.

Reply With Quote
  #30  
Old August 22nd, 2008, 03:00 PM
IAmALlama IAmALlama is online now
Me
Click here for more information. Click here for more information
Click here for more information
 
Join Date: Apr 2007
Location: Seattle, WA
Posts: 1,907 IAmALlama User rank is Private First Class (20 - 50 Reputation Level)IAmALlama User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 4 Days 16 h 43 m 30 sec
Reputation Power: 4
well you can still use the other $count method to get the correct count if you want, but it shouldn't be needed. The subquery should just get a count of how many rows share the name of the primary query. That should essentially get the count of how many criteria there are under that name. I guess though you would need to add the criteria part to that query too to get a count of how many match the criteria also. Try this:
PHP Code:
 $q1 "SELECT *, (SELECT COUNT(*) FROM TableName AS t2 WHERE `Name`=`TableName`.`Name` AND ($criteria)) AS `count` FROM TableName WHERE (".$criteria.") ORDER BY `count`, `Name`, `Criteria`"

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Showing results for Mysql Query multiple results for each name


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
Stay green...Green IT