1
JS
Help with a php function for my project
  • 2010/2/16 23:32

  • JS

  • Just popping in

  • Posts: 87

  • Since: 2002/12/16


I am currently working on some different things with the old KShop module and one thing that I am working on is adding jpgraphs to the module.

I am not an expert with PHP but I can hack my way through it. one thing I am trying to do is build a function to query how much of each product is sold and put it into an array to be used with jpgraph

It would be great if someone could help guide me in the right direction.

There is a table in the datablase where KShop writes how much of each product is sold and this is where I want to pull the data from.

here is some raw output from the .sql file for that table

(`id`, `order_id`, `qty`, `p_num`, `p_name`, `p_price`) VALUES (113'A01''Apples  Option: Braeburn''12.00')


Now what I am trying to do is build a function that will query the qty (quantity) of each item ordered.

for example the array would have the following

25 apples
100 oranges
30 cookies
ect..

The values that I want to put into jpgraph is the following
total amount of each product sold
the name of each product to associate with the amount

I figured I will need to query the colums qty, p_num, p_name

here is a copy of the code I have so far. I know this does not return what I want but I was hopeing that someone could help me fix it.

function loadstats(){
    global 
$xoopsDB,$xoopsModuleConfig;
    
$stat=array();
    
    
$query $xoopsDB->query(' SELECT * FROM ' $xoopsDB->prefix('kshop_orders_products'));
    while (
$row $xoopsDB->fetchArray($query))
    {
        
$stat['qty']=$row['qty'];
        
$stat['p_num']=$row['p_num'];
        
$stat['p_name']=$row['p_name'];
        
    }

    return 
$stat;
}


Thanks!

2
Mazar
Re: Help with a php function for my project
  • 2010/2/17 6:15

  • Mazar

  • Not too shy to talk

  • Posts: 191

  • Since: 2009/1/4 0


function loadstats(){
    global 
$xoopsDB,$xoopsModuleConfig;
    
$stat=array();
    
$i=1;
    
$query $xoopsDB->query(' SELECT * FROM ' $xoopsDB->prefix('kshop_orders_products'));
    while (
$row $xoopsDB->fetchArray($query))
    {
        
$stat[$i]['qty']=$row['qty'];
        
$stat[$i]['p_num']=$row['p_num'];
        
$stat[$i]['p_name']=$row['p_name'];
        
$i++;
    }

    return 
$stat;
}


3
ghia
Re: Help with a php function for my project
  • 2010/2/17 13:31

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Is it not the intention to have the quantity of apples from all orders (counted togheter)?

4
kaotik
Re: Help with a php function for my project
  • 2010/2/17 15:15

  • kaotik

  • Just can't stay away

  • Posts: 861

  • Since: 2004/2/19


Hi
Some graphs would definitly be nice for kshop :)
I stopped developing kshop some time ago so it's nice to see someone else picking up this module.
If you like I'll place you as module developer for this module at dev.xoops.org

5
JS
Re: Help with a php function for my project
  • 2010/2/17 16:28

  • JS

  • Just popping in

  • Posts: 87

  • Since: 2002/12/16


ghia - you are correct that is what I am trying to do.

Kaotik - Sure I wouldn't mind that I have quite a bit more I would like to do with the module before I call it good and that would give me a place to release the module as well.

My intent is to keep KShop as light weight as possible but yet make it usable and easy to change if need be.

6
JS
Re: Help with a php function for my project
  • 2010/2/17 19:11

  • JS

  • Just popping in

  • Posts: 87

  • Since: 2002/12/16


kaotik

I registerd at dev.xoops.org however I did not see the KShop project there.

maybe I am looking in the wrong place?

I will check to see if it is up on sourceforge as well.

Thanks!

7
ghia
Re: Help with a php function for my project
  • 2010/2/17 19:31

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


It is here.

For the category and products list, I have doubts about the scalebility. It seems that the full product list is run through for every category, meaning that 10 categories with an average of 10 products require 1000 iterations, while 100 would be sufficient.
Try also to move the CSS out of the template by using class or name.

For the graph, you can use this query
$query $xoopsDB->query(' SELECT SUM(`qty`) as 'total_qty', `p_name` FROM ' $xoopsDB->prefix('kshop_orders_products'). ' GROUP BY `p_num`, `p_name` ORDER BY `p_name`');

8
JS
Re: Help with a php function for my project
  • 2010/2/17 19:33

  • JS

  • Just popping in

  • Posts: 87

  • Since: 2002/12/16


Thanks! wonder why it didn't come up in the search. is xoopsforge not intergrated with XOOPS search?

9
ghia
Re: Help with a php function for my project
  • 2010/2/17 19:51

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Humm, it seems the project module (xtrove) is not included in the search. Should be handy!

10
JS
Re: Help with a php function for my project
  • 2010/2/17 20:06

  • JS

  • Just popping in

  • Posts: 87

  • Since: 2002/12/16


Thanks ghia!

Ok this is what I was going to try.... let me know your thoughts.. was I on the right track :)

(' SELECT qty COUNT(*) FROM ' $xoopsDB->prefix('kshop_orders_products') . ' GROUP BY p_name ' );


This is with your code I will have to test it out later. but let me know if I am formating it correctly

function loadstats(){ 
    global 
$xoopsDB,$xoopsModuleConfig
    
$stat=array(); 
     
    
$query $xoopsDB->query(' SELECT SUM(`qty`) as 'total_qty', `p_name` FROM ' $xoopsDB->prefix('kshop_orders_products'). ' GROUP BY `p_num`, `p_name` ORDER BY `p_name`');
 
    while (
$row $xoopsDB->fetchArray($query)) 
    { 
        
$stat['qty']=$row['qty']; 
        
$stat['p_num']=$row['p_num']; 
        
$stat['p_name']=$row['p_name']; 
         
    } 

    return 
$stat
}



As for the cat and product lists that I was working on is there a better way I could do that? I was looking at the suggestion you had linked in but I was having trouble translating into what I was trying to do

I get to use my "new to php codeing" card on that one :P

Thanks for all your help

Login

Username:
Password:

Lost Password? Register now!

Who's Online

69 user(s) are online (37 user(s) are browsing Support Forums)


Members: 0


Guests: 69


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits