Jump to content

my sql maches


lioslios

Recommended Posts

guys i have 2 tables one is the product table and holds the id,productname,price

and second tables is the daysales and holds the slles of the day in the fiels id,productname,price,seller,datetime...

 

my script works as: if a saler sells somthing then the sale stores to the daysales table!

 

and in the end of day i  use a button to diplay the intire table on the webpage and this works too!!!

 

 

 

 

 

if(isset($_POST['sub11']))

            {

                                if ($_SESSION['read_data']==1)

 

                                                {

                            $result = mysql_query("SELECT * FROM $serv");

                           

                           

                            while ($row = mysql_fetch_assoc($result))

                                            {

                                                    echo "<tr>";

                                                foreach($row as $cell)

 

                                                    echo "<td ALIGN=\"center\">$cell<FONT></td>"; 

 

                                                echo "</tr>\n";

                                            }

                                }

           

           

            }

                               

 

 

BUT I WAND TO ADD  a second table that displays the "same products" e.g. if  the product car sells more than one time

 

then i wand to get the car is 3 times selled!!!

the boat 6 times

...

...

...

 

 

any idea for this?

 

 

thanks

Link to comment
Share on other sites

ok this works fine!

 

one more question,

 

i get the similar products eg cars says 20 but in the records i have and the quantity field that says 5 cars for a record so the count must be productname * quantity for each record!

 

the result is xorrect only if quantity is 1

 

 

 

$result = mysql_query("SELECT  id,productname,price,quantity,finalprice,seller,datetime, COUNT(productname)AS num FROM orderhistory  GROUP BY productname ORDER BY num DESC");

                           

                           

                            while ($row = mysql_fetch_assoc($result))

                                            {

                                                    echo "<tr>";

                                                foreach($row as $cell)

 

echo "<td ALIGN=\"center\">$cell<FONT></td>"; 

 

                                                echo "</tr>\n";

                                            }

 

 

 

thanks

Link to comment
Share on other sites

my english is no so good sorry

 

can i use this??

 

COUNT(productname*quantity)

 

sample tabe

 

quantity*******productname

    1                            car

    1                            car

    2                            boat

    1                            boat

    1                            car

 

 

so to get the resault

 

boat  = 3

car    = 3

 

as it is this time i get

boat  = 2

car    = 3

 

 

 

thanks

 

 

 

 

 

Link to comment
Share on other sites

You didn't mention the quantity field in your first post. If you want the total of all quantities for a product, you would use SUM(quantity) instead of COUNT(product). Use the same GROUP BY, and you should be fine.

 

SELECT productname, SUM(quantity)
FROM daysales
GROUP BY productname

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.