teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

文法の修正

2021/10/29 06:24

投稿

退会済みユーザー
title CHANGED
@@ -1,1 +1,1 @@
1
- elseif文をひとまとめにして、javascriptで活用したい
1
+ -----------------------------
body CHANGED
@@ -1,66 +1,1 @@
1
- htmlで、テキストボックスに入力した2つの値を掛けた結果を出す部分の作り方に困っています。
2
-
3
- 単価 x
4
- 数量 y
5
- 合計 z
6
-
7
- この合計「z」の部分です。
8
- x,yはそれぞれphpで作成しており、入力したデータはDBに保存するような形で、構文はeiseif文で複数行あります。
9
- このx,y2つのelseif複数構文をひとまとめにして、z部分で簡単に「x*y」といった感じで書こうとしているのですがなにかいい方法はありませんか。
10
-
11
-
12
- 追記:
13
- 初投稿なもので、情報足らずな質問にもかかわらず皆様ご指摘していただきありがとうございます。
14
- (補足)
15
- 単価xのコード↓
16
- ```php
17
- <?php
18
-
19
- if (isset($_SESSION['state'])) {
20
- if (! empty($aaa) && empty($aaa['price'])) {
21
- echo '<input type="text" name="price" required>';
22
- } elseif (! empty($aaa) && ! empty($aaa['price'])) {
23
- echo '<input type="text" name="price" value="' . h($row1['price']) . '">';
24
- }
25
- } elseif (isset($_SESSION['regist_else'])) {
26
- if (! empty($aaa) && ! empty($aaa['price'])) {
27
- echo h($aaa['_price']);
28
- }elseif (! empty($_SESSION['error_price'])) {
29
- echo '<input type="text" name="price" value="' . h($_SESSION['error_price']) . '">';
30
- } else {
31
- echo '<input type="text" name="price" >';
32
- }
33
- } else {
34
- echo '<input type="text" name="price" >';
35
- }
36
- ?>
37
- ```
38
-
39
- 数量yのコード↓
40
- ```php
41
- if (isset($_SESSION['state'])) {
42
- if (! empty($aaa) && empty($aaa['quantity'])) {
43
- echo '<input type="number" min="0" name="quantity">';
44
- } elseif (! empty($aaa) && ! empty($aaa['quantity'])) {
45
- echo '<input type="number" min="0" name="quantity" value="' . h($aaa['quantity']) . '">';
46
- }
47
- }
48
- elseif (isset($_SESSION['regist_else'])) {
1
+ ---------------------------------------------------
49
- if (! empty($aaa) && ! empty($aaa['quantity'])) {
50
- echo h($aaa['quantity']);
51
- }
52
- } elseif (isset($_SESSION['regist_error'])) {
53
- if (! empty($_SESSION['error_quantity'])) {
54
- echo '<input type="number" min="0" name="quantity" value="' . h($_SESSION['error_quantity']) . '"required>';
55
- } else {
56
- echo '<input type="number" min="0" name="quantity">';
57
- }
58
- } else {
59
- echo '<input type="number" min="0" name="quantity">';
60
- }
61
-
62
- ?>
63
- ```
64
-
65
- x,yはこのようにコーディングしました。
66
- これらを掛算したものをzに表示するには、どうしたらいいでしょうか。

3

文法の修正

2021/10/29 06:24

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  この合計「z」の部分です。
8
8
  x,yはそれぞれphpで作成しており、入力したデータはDBに保存するような形で、構文はeiseif文で複数行あります。
9
- このx,y2つのelseif複数構文をひとまとめにして、z部分でjavascriptで簡単に「x*y」といった感じで書こうとしているのですがなにかいい方法はありませんか。
9
+ このx,y2つのelseif複数構文をひとまとめにして、z部分で簡単に「x*y」といった感じで書こうとしているのですがなにかいい方法はありませんか。
10
10
 
11
11
 
12
12
  追記:
@@ -20,18 +20,18 @@
20
20
  if (! empty($aaa) && empty($aaa['price'])) {
21
21
  echo '<input type="text" name="price" required>';
22
22
  } elseif (! empty($aaa) && ! empty($aaa['price'])) {
23
- echo '<input type="text" name="price" value="' . h($row1['price']) . '"required>';
23
+ echo '<input type="text" name="price" value="' . h($row1['price']) . '">';
24
24
  }
25
25
  } elseif (isset($_SESSION['regist_else'])) {
26
26
  if (! empty($aaa) && ! empty($aaa['price'])) {
27
27
  echo h($aaa['_price']);
28
28
  }elseif (! empty($_SESSION['error_price'])) {
29
- echo '<input type="text" name="price" value="' . h($_SESSION['error_price']) . '"required>';
29
+ echo '<input type="text" name="price" value="' . h($_SESSION['error_price']) . '">';
30
30
  } else {
31
- echo '<input type="text" name="price" required>';
31
+ echo '<input type="text" name="price" >';
32
32
  }
33
33
  } else {
34
- echo '<input type="text" name="price" required>';
34
+ echo '<input type="text" name="price" >';
35
35
  }
36
36
  ?>
37
37
  ```
@@ -40,9 +40,9 @@
40
40
  ```php
41
41
  if (isset($_SESSION['state'])) {
42
42
  if (! empty($aaa) && empty($aaa['quantity'])) {
43
- echo '<input type="number" min="0" name="quantity" required>';
43
+ echo '<input type="number" min="0" name="quantity">';
44
44
  } elseif (! empty($aaa) && ! empty($aaa['quantity'])) {
45
- echo '<input type="number" min="0" name="quantity" value="' . h($aaa['quantity']) . '"required>';
45
+ echo '<input type="number" min="0" name="quantity" value="' . h($aaa['quantity']) . '">';
46
46
  }
47
47
  }
48
48
  elseif (isset($_SESSION['regist_else'])) {
@@ -53,10 +53,10 @@
53
53
  if (! empty($_SESSION['error_quantity'])) {
54
54
  echo '<input type="number" min="0" name="quantity" value="' . h($_SESSION['error_quantity']) . '"required>';
55
55
  } else {
56
- echo '<input type="number" min="0" name="quantity" required>';
56
+ echo '<input type="number" min="0" name="quantity">';
57
57
  }
58
58
  } else {
59
- echo '<input type="number" min="0" name="quantity" required>';
59
+ echo '<input type="number" min="0" name="quantity">';
60
60
  }
61
61
 
62
62
  ?>

2

文法の修正

2021/10/28 11:55

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -62,4 +62,5 @@
62
62
  ?>
63
63
  ```
64
64
 
65
+ x,yはこのようにコーディングしました。
65
66
  これらを掛算したものをzに表示するには、どうしたらいいでしょうか。

1

コードの追記

2021/10/28 02:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -6,4 +6,60 @@
6
6
 
7
7
  この合計「z」の部分です。
8
8
  x,yはそれぞれphpで作成しており、入力したデータはDBに保存するような形で、構文はeiseif文で複数行あります。
9
- このx,y2つのelseif複数構文をひとまとめにして、z部分でjavascriptで簡単に「x*y」といった感じで書こうとしているのですがなにかいい方法はありませんか。
9
+ このx,y2つのelseif複数構文をひとまとめにして、z部分でjavascriptで簡単に「x*y」といった感じで書こうとしているのですがなにかいい方法はありませんか。
10
+
11
+
12
+ 追記:
13
+ 初投稿なもので、情報足らずな質問にもかかわらず皆様ご指摘していただきありがとうございます。
14
+ (補足)
15
+ 単価xのコード↓
16
+ ```php
17
+ <?php
18
+
19
+ if (isset($_SESSION['state'])) {
20
+ if (! empty($aaa) && empty($aaa['price'])) {
21
+ echo '<input type="text" name="price" required>';
22
+ } elseif (! empty($aaa) && ! empty($aaa['price'])) {
23
+ echo '<input type="text" name="price" value="' . h($row1['price']) . '"required>';
24
+ }
25
+ } elseif (isset($_SESSION['regist_else'])) {
26
+ if (! empty($aaa) && ! empty($aaa['price'])) {
27
+ echo h($aaa['_price']);
28
+ }elseif (! empty($_SESSION['error_price'])) {
29
+ echo '<input type="text" name="price" value="' . h($_SESSION['error_price']) . '"required>';
30
+ } else {
31
+ echo '<input type="text" name="price" required>';
32
+ }
33
+ } else {
34
+ echo '<input type="text" name="price" required>';
35
+ }
36
+ ?>
37
+ ```
38
+
39
+ 数量yのコード↓
40
+ ```php
41
+ if (isset($_SESSION['state'])) {
42
+ if (! empty($aaa) && empty($aaa['quantity'])) {
43
+ echo '<input type="number" min="0" name="quantity" required>';
44
+ } elseif (! empty($aaa) && ! empty($aaa['quantity'])) {
45
+ echo '<input type="number" min="0" name="quantity" value="' . h($aaa['quantity']) . '"required>';
46
+ }
47
+ }
48
+ elseif (isset($_SESSION['regist_else'])) {
49
+ if (! empty($aaa) && ! empty($aaa['quantity'])) {
50
+ echo h($aaa['quantity']);
51
+ }
52
+ } elseif (isset($_SESSION['regist_error'])) {
53
+ if (! empty($_SESSION['error_quantity'])) {
54
+ echo '<input type="number" min="0" name="quantity" value="' . h($_SESSION['error_quantity']) . '"required>';
55
+ } else {
56
+ echo '<input type="number" min="0" name="quantity" required>';
57
+ }
58
+ } else {
59
+ echo '<input type="number" min="0" name="quantity" required>';
60
+ }
61
+
62
+ ?>
63
+ ```
64
+
65
+ これらを掛算したものをzに表示するには、どうしたらいいでしょうか。