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:
  #31  
Old August 22nd, 2008, 03:04 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
Ahhhh haaaaaa That worked perfect thanks ALA!!

Now all I need to do is end the div "</div>" on the last $a1['Criteria'] I tried it with an if command but it does not work

I think I am missing something that needs to tell it when its the last Criteria?

Thanks

Reply With Quote
  #32  
Old August 22nd, 2008, 03:52 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 managed to get it all working the only trouble is I have a random count which appears at the top of the page which I cannot get rid off!?!

PHP Code:
<?PHP
  $n 
0;
  
$count 0
 
while(
$a1 mysql_fetch_array($r1))
    {    
    if (
$a1["Name"] != $fundn
        {  
            echo 
"</div>"
            echo 
'</td><td align="center" valign="top">';
            echo 
$a1['count'];
            echo 
"</td></tr>";
?>
  <tr>
    <td valign="top">
    <script language="JavaScript">
    expanded[<?php echo $n?>] = 0
    </script>
<?PHP
        $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']."<br>";

        
        
$fundcheck $a1["Name"];
   }
?>


Any suggestions guys??

Thanks for all the help!

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

Reply With Quote
  #33  
Old August 22nd, 2008, 03:56 PM
IAmALlama IAmALlama is offline
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,937 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 5 Days 1 h 54 m 18 sec
Reputation Power: 4
in all honesty, I was just working on it and couldn't get it it to display properly without some major changes and that even had a mistake with the count not working without setting another variable containing the count from the last loop and more. I would actually suggest re-writing it so the query results are put into a multi-dimensional array and loop through those results for displaying them out.

something kinda like:
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`";   

while(
$a1 mysql_fetch_array($r1)){
    
//put all the results into a multi-dimensional array.
    
$results[$a1['Name']][] = $a1['Criteria'];
}

$n 0;
//loop through the outter array.
foreach($results as $Name=>$value){
    
$n++;
    echo<<<HTML
  <tr> 
    <td valign="top"> 
      <script language="JavaScript">
      expanded
[{$n}] = 0
      </script>
HTML;
    echo 
"      <img src=\"Images/" . (($expanded[$n] == 0) ? "plus" "minus") . ".gif\" name=\"image$n\" id=\"image$n\" onclick=\"toggle($n)\">  {$Name}\n";
    echo 
"      <div id=\"criteria$n\" style=\"font-size: 12px; color: #666666; margin-top: 10px; margin-bottom: 10px;" . (($expanded[$n] == 0) ? "display: none" "") . "\">\n";
    
//loop through each criteria
    
foreach($value as $Criteria){
        echo 
"        {$Criteria}\n";
    }
    echo 
"      </div>\n";
    echo 
"    </td>\n";
    echo 
"    <td align=\"center\" valign=\"top\">\n"
    echo 
"      ".count($value); 
    echo 
"    </td>\n  </tr>\n"
}

That should do everything your script does and it was definately easier to write.

And if you look at the source of the code you originally had it was improper and wasn't well formed. This is complete and valid and is even formatted with spaces and such to make the source look readable.

Last edited by IAmALlama : August 22nd, 2008 at 04:00 PM.

Reply With Quote
  #34  
Old August 22nd, 2008, 05:32 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
Ahh yes the only trouble with making an array is it takes a little longer to load, although your code works perfect

The only bit left wrong with mine was the first count showing above the data, and yes its a bit messy

Reply With Quote
  #35  
Old August 22nd, 2008, 05:45 PM
IAmALlama IAmALlama is offline
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,937 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 5 Days 1 h 54 m 18 sec
Reputation Power: 4
I would be willing to bet that there is just a few millisecond difference between the average time of the two scripts. Try benchmarking both and you will probably see that the times run close enough that no one would notice. In all honesty, you would probably see the times jump around enough that the high times of the single loop code would probably be above the low times of the 3 loop code. Meaning that at any given time either one could be faster.

Reply With Quote
  #36  
Old August 22nd, 2008, 05:56 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
Well in firefox there is a great difference but in internet explorer there is not much of a difference and internet explorer is the most use browser so Ill go with your script!! Thanks!!!

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 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek