0

hi everyone

got an issue trying to get certain results from a list generated from a database..
ill try and set the scenario

basically i want the same thing as the left hand menu here https://www.elance.com/r/jobs/cat-design-multimedia/
...if you notice at the sides of the categorys theres a value of how many projects are posted, then in the groups theres the total amount for each group.

ive been trying to do this same thing but its drivin me mad. originally ive been trying using php, i then had a friend try with sql, but he got very carried away and started reccomending recoding whole parts of the script...that ended sharply lol.... now im thinkin mybe javascript would be a good idea? but i have not much knowledge of it at all so im stumped...

from the database i have returned the following results...

categorys
groups
all projects posted

i somehow need to check all project categories against site categories, and return a number based on how many projects are found

then i need to calculate how many results are found in that group of categories and return that number

is this possible with js? or a friendly php way?

thanks

2
Contributors
5
Replies
8
Views
5 Years
Discussion Span
Last Post by LastMitch
0

@shlokka

i somehow need to check all project categories against site categories, and return a number based on how many projects are found

i somehow need to check all project categories against site categories, and return a number based on how many projects are found

then i need to calculate how many results are found in that group of categories and return that number

Can you provide the query from the database?

The query will make more sense than just guessing what you are doing.

Since you have a database I think php will do. Here is a link on how to group the categories by using those functions:

http://www.htmlgoodies.com/primers/database/article.php/3478101/Database-Basics-Part-6.htm

0

hi, the problem isnt grouping the categories, its getting how many live projects match each category, and then returning the number of how many next to the right category

i am using codeigniter framework

heres the code ... the variable $projectdetails is returning all of the projects table.
$groupswithcategories combines the groups and categories datyabases and then splits them according to right group using the $i variable.
the rest should be self explanitory

            <a class="type">By Job Category</a>
                    <a class="simple"><b>All</b><span>(<?php echo count($projectdetails->result());?>)</span></a>

                <ul class="category">
                       <?php
                      if(isset($groupsWithCategories) and count($groupsWithCategories)>0 )
                      {

                  $number = count($groupsWithCategories);

                    $i = 1;              
                        foreach($groupsWithCategories as $groupsWithCategory)
                        {
                        //   for ($i =0; $i<=$number; $i++){  
                          if($groupsWithCategory['num_categories']>0)
                          {        
                $i = $i+1;
             ?>

          <li class="cat_hd"><a href="#collapse<?php echo $i;?>" class="nav-toggle">                 
                  <?php echo $groupsWithCategory['group_name']?>
                  <span>(4,924)</span></a></li>


                  <div id="collapse<?php echo $i;?>" style="display:none">


                    <?php } 
                    $i= $i;

                    foreach($groupsWithCategory['categories']->result() as $category)
                    {
                     if($i%3 ==0)

                  echo $i;
                    ?>

                <li>
                        <label class="myCheckbox"><input type="checkbox" name="catname" /><span></span></label>
                        <a href="<?php echo site_url('project/category/'.$category->category_name); ?>">
                        <?php echo $category->category_name; ?><span>(<?php 

  foreach($projectdetails->result() as $pridd){
if($pridd->project_categories == $category->category_name){
//echo count($pridd);
//$priddd = group($pridd);
echo count($pridd);
 } 

}

?>)</span></a>
                        </li>        

                  <?php
                   } //Foreach End - Traverse Category
                  ?>
                </div>  
                  <?php
                    //      }//Check For Cateogry Availability
                      } //For Each Travesal - For Group
                    }//If End - Check For Group Existence
                  ?>

thanks in advance

0

@shlokka

hi, the problem isnt grouping the categories, its getting how many live projects match each category, and then returning the number of how many next to the right category

I'm not familiar codeigniter framework

But I still don't see any query anywhere in your code?

Here is the link on an example that has a querys:

http://codeigniter.com/user_guide/database/active_record.html

http://codeigniter.com/user_guide/database/results.html

A query should look like this, I got that from the link:

$query = $this->db->query("SELECT * FROM my_table");

foreach ($query->result_array() as $row)
{
   echo $row['title'];
   echo $row['name'];
   echo $row['body'];
}

In order to get how many live projects match each category returning the number of how many next to the right category. Then you need a query! Where is the query?

Edited by LastMitch: grammer

0

hi...i have managed to get the correct results for categories by doing the following edit

                <li>
                        <label class="myCheckbox"><input type="checkbox" name="catname" /><span></span></label>
                        <a href="<?php echo site_url('project/category/'.$category->category_name); ?>">
                        <?php echo $category->category_name; ?><span>(<?php 

  $getinfo = array('projects.project_categories' => $category->category_name);
  $shut = $this->skills_model->getProjects($getinfo);
  echo count($shut->result());

but now i need to find a way of calculating the total amount from each category for that given group

0

@shlokka

You still need a query. how would you calculate the total amount from each category for that given group without a query gathering the total amount?

Edited by LastMitch: grammer

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.