Answer the question
In order to leave comments, you need to log in
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
behind the loop variable sum=0, loop through the collection and in each iteration sum += P
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.
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.
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.
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
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 ''
);
$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);
$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);
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question