V
V
Vladimir Kai2017-02-08 10:08:54
Delphi
Vladimir Kai, 2017-02-08 10:08:54

How to calculate the cost of an order in Delphi?

Good afternoon!
Maybe someone will help .. well, or direct.
There is an array of goods - T with a subscript i
The number of goods is indicated - N
Cost of goods in the order - P1
Shipping cost - P2 (Determined separately and we will assume that it has already been calculated)
Total cost - P
It is required in the cycle to determine the total amount of the order by multiplying the quantity each item for its value.
And finally, add P1 and P2, getting P.
How to organize this in a cycle? Maybe you need to introduce more variables?
And how approximately it will look in Delphi?

Answer the question

In order to leave comments, you need to log in

8 answer(s)
L
leremin, 2017-02-08
@leremin

behind the loop variable sum=0, loop through the collection and in each iteration sum += P

X
xmoonlight, 2017-02-08
@xmoonlight

P=[E(i=0,N-1)]T*N+P2
(E - sum sign)

K
kalapanga, 2017-02-08
@kalapanga

You can only send it to a secondary school. The problem is from there. If there is a problem with the programming language, then you should at least write something yourself, try it. If it doesn't work, we'll see and fix it.

V
Vladimir Kai, 2017-02-08
@gold_dezmor

program Massiv;

var 
T: array [i..j] of integer; 
i, j, N: integer;

P, P1, P2: integer; 

begin

P2 := 300;

    for i := 0 to j do
        begin
        
        P1 := T[i]*N;
        i := i+1;
        end;
   
P := P1 + P2;
end.

S
sim3x, 2017-09-20
@sim3x

1) What type of field to use and in general how is the picture stored there, in the form of a set of bytes?
blob
2) The question stemming from the previous one is how to make an insert request and specify it as jpg, png, gif, etc.?
A separate field indicating the type.
Or do the magic of recognizing the file type by magic php.net/manual/en/function.mime-content-type.php
Or (correct solution) after uploading the file, cast it to one type (jpg, png, webm)
Or even like this https: //stackoverflow.com/a/21732109
3) How to display on the page? When we just give a picture using php, everything is clear there header, we give the file header, then the file itself and everything is ok, but here the header has already been transferred and is it a regular page or is there something like src="getimage.php?id=738" where the php script already forms and gives each picture?
but no way. When the browser requests this url, php should generate a response with the correct content type, so before starting the return, you will need to completely get the image itself from the database

I
Ivan, 2017-09-20
@helpik94

First, make a table to store pictures:

create table testblob (
    image_id        tinyint(3)  not null default '0',
    image_type      varchar(25) not null default '',
    image           blob        not null,
    image_size      varchar(25) not null default '',
    image_ctgy      varchar(25) not null default '',
    image_name      varchar(50) not null default ''
);

Then:
$imgData = file_get_contents($filename);
$size = getimagesize($filename);
mysql_connect("localhost", "$username", "$password");
mysql_select_db ("$dbname");
// mysqli 
// $link = mysqli_connect("localhost", $username, $password,$dbname); 
$sql = sprintf("INSERT INTO testblob
    (image_type, image, image_size, image_name)
    VALUES
    ('%s', '%s', '%d', '%s')",
   
    mysql_real_escape_string($size['mime']),
    mysql_real_escape_string($imgData),
    $size[3],
    mysql_real_escape_string($_FILES['userfile']['name'])
    );
mysql_query($sql);

To display an image on a web page:
$link = mysql_connect("localhost", "username", "password");
mysql_select_db("testblob");
$sql = "SELECT image FROM testblob WHERE image_id=0";
$result = mysql_query("$sql");
header("Content-type: image/jpeg");
echo mysql_result($result, 0);
mysql_close($link);

K
kvg1956, 2019-03-27
@kvg1956

The issue of storing graphic files in MySQL can be solved in another way: create a folder for graphic files in the file system and, after uploading them to this folder, write the names of these files to the MySQL database. This way the database server will not be overloaded. In general, this is even easier to do. I can provide code if needed.
Beginner in programming using MySQL

N
Nurlan, 2017-09-20
@daager

1) Blob
2) www.php-mysql-tutorial.com/wikis/mysql-tutorials/u...
3) www.php-mysql-tutorial.com/wikis/mysql-tutorials/u...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question