質問編集履歴
2
コードの全体像を追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,3 +67,225 @@
|
|
67
67
|
何日も解決できておらず、困っております。
|
68
68
|
|
69
69
|
宜しくお願い致します。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
```$during = $_POST[during];
|
90
|
+
|
91
|
+
$year = $_POST[year];
|
92
|
+
|
93
|
+
$month = $_POST[month];
|
94
|
+
|
95
|
+
$day = $_POST[day];
|
96
|
+
|
97
|
+
date_default_timezone_set('Asia/Tokyo');
|
98
|
+
|
99
|
+
define('TERM', $during);//1週間表示
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
$date_data=array();
|
104
|
+
|
105
|
+
$date = date($year."-".$month."-".$day);//今日の日付
|
106
|
+
|
107
|
+
//$date = date("2021-02-01");//今日の日付
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
print("名前");
|
116
|
+
|
117
|
+
for( $i=0; $i<TERM; $i++){
|
118
|
+
|
119
|
+
$timestamp = strtotime($i.' day ' . $date);
|
120
|
+
|
121
|
+
$a=date('Y/m/d', $timestamp).",,,,";
|
122
|
+
|
123
|
+
print($a);
|
124
|
+
|
125
|
+
$days=$days.$a;
|
126
|
+
|
127
|
+
//$days=$days.$a."\n";
|
128
|
+
|
129
|
+
$date_data[] = date("Y-m-d", $timestamp);
|
130
|
+
|
131
|
+
}
|
132
|
+
|
133
|
+
print("<br>");
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
// ----------------------------------------------------------------------
|
140
|
+
|
141
|
+
$db=mysqli_connect("localhost","kunren_rensyu","2vFz44k@","admin_kunren"); //データベース名、ユーザ名、パスワード、利用するデータベース
|
142
|
+
|
143
|
+
mysqli_set_charset($db,"utf8"); //文字化け対策
|
144
|
+
|
145
|
+
//print("接続完了");
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
/*名前取り出し*/
|
152
|
+
|
153
|
+
$query = "select no,sei,mei from suga_player where del_flg = 0";
|
154
|
+
|
155
|
+
$result = mysqli_query($db,$query) or die("クエリエラー".mysqli_error($db));
|
156
|
+
|
157
|
+
while($row = mysqli_fetch_array($result)) {
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
$c=$row[sei].$row[mei].",";
|
166
|
+
|
167
|
+
$allName=$allName.",".$c."\n";
|
168
|
+
|
169
|
+
print($allName);
|
170
|
+
|
171
|
+
/*$all='';*/
|
172
|
+
|
173
|
+
for( $i=0; $i<TERM; $i++){
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
//名前IDと登録日が一致したデータ取り出し
|
178
|
+
|
179
|
+
$query2 = "select student_no,torokubi,taion,reason,shukketu,other,hurigana from suga_shukketu where torokubi='".$date_data[$i]."'and student_no =".$row[0]." order by hurigana asc";
|
180
|
+
|
181
|
+
$result2 = mysqli_query($db,$query2) or die("クエリエラー".mysqli_error($db));
|
182
|
+
|
183
|
+
$row2 =mysqli_fetch_array($result2);
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
$n=$i + 1;
|
188
|
+
|
189
|
+
if($row2 == false) {
|
190
|
+
|
191
|
+
$b=" , , , ,";
|
192
|
+
|
193
|
+
//$all=$all.$b."\n";
|
194
|
+
|
195
|
+
if(($n % $during) == 0){
|
196
|
+
|
197
|
+
$all=$all.$b."\n";
|
198
|
+
|
199
|
+
print($b);
|
200
|
+
|
201
|
+
}else{
|
202
|
+
|
203
|
+
$all=$all.$b;
|
204
|
+
|
205
|
+
print($b);
|
206
|
+
|
207
|
+
}
|
208
|
+
|
209
|
+
} else {
|
210
|
+
|
211
|
+
if(($n % $during) == 0){
|
212
|
+
|
213
|
+
$br="\n";
|
214
|
+
|
215
|
+
$b=$row2[3].",".$row2[2].",".$row2[4].",".$row2[5].",";
|
216
|
+
|
217
|
+
print($b);
|
218
|
+
|
219
|
+
$all=$all.$b.$br;
|
220
|
+
|
221
|
+
//$all=$all.$b."\n";
|
222
|
+
|
223
|
+
}else{
|
224
|
+
|
225
|
+
$b=$row2[3].",".$row2[2].",".$row2[4].",".$row2[5].",";
|
226
|
+
|
227
|
+
print($b);
|
228
|
+
|
229
|
+
$all=$all.$b;
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
print("<br>");
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
//$alls='名前,'.$days."\n".$sei_mei.",".$all."\n";
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
/*$alls=$allName.$days."\n".$all;
|
250
|
+
|
251
|
+
$data = mb_convert_encoding($alls, 'SJIS-win', 'UTF-8');
|
252
|
+
|
253
|
+
$f=fopen("ichiran.csv","w");
|
254
|
+
|
255
|
+
fputs($f,$data);
|
256
|
+
|
257
|
+
fclose($f);*/
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
$allNames="\n".$allName; //名前を書き込み
|
264
|
+
|
265
|
+
$data1 = mb_convert_encoding($allNames, 'SJIS-win', 'UTF-8');
|
266
|
+
|
267
|
+
$f=fopen("ichiran.csv","w");
|
268
|
+
|
269
|
+
fputs($f,$data1);
|
270
|
+
|
271
|
+
fclose($f);
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
$allDatas=$days."\n".$all; //それぞれの情報を追加書き込み
|
276
|
+
|
277
|
+
$data2 = mb_convert_encoding($allDatas, 'SJIS-win', 'UTF-8');
|
278
|
+
|
279
|
+
$f=fopen("ichiran.csv","a");
|
280
|
+
|
281
|
+
fputs($f,$data2);
|
282
|
+
|
283
|
+
fclose($f);
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
print("<a href='ichiran.csv' download>ここからダウンロード</a>");
|
288
|
+
|
289
|
+
コード
|
290
|
+
|
291
|
+
```
|
1
画像を挿入しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
PHPでcsvに
|
1
|
+
PHPでcsvに既にあるデータの横に追加書き込みをする方法
|
test
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
phpでcsv出力を試みています。
|
2
2
|
|
3
|
-
①名前を
|
3
|
+
①名前を書き込む
|
4
4
|
|
5
5
|
②追加書き込みモード(a)でそれぞれの名前の横に情報を書き込む
|
6
6
|
|
@@ -12,11 +12,15 @@
|
|
12
12
|
|
13
13
|
**完成イメージ**
|
14
14
|
|
15
|
+
![イメージ説明](ccd01d3436e5382b1cbbb3586c3a1e40.png)
|
16
|
+
|
15
17
|
https://gyazo.com/d7801185eb00a9788a42787410bf3dbc
|
16
18
|
|
17
19
|
|
18
20
|
|
19
21
|
**現在の状態**
|
22
|
+
|
23
|
+
![![イメージ説明](734c9410d54223483bad311e05b667c2.png)](90673deea85887eb460485ed8c0e7c68.png)
|
20
24
|
|
21
25
|
https://gyazo.com/e234954829af0b534858759fa625c63d
|
22
26
|
|