我正在尝试在3x4表中输出这些数组。目前它只输出1列数组中新行中每个数组的第一个值。虽然它应该是3列,其中'qualitypoint','quality'和'q'彼此相邻。然后在一排新的'技术','技术'和't'旁边彼此等。
import sqlite3
import decimal
import os
import sys
import uuid
VERSION = "oops"
DEVICE_SOFTWARE_VERSION = "OOPS"
FILENAME = "VHOURS.txt"
conn = sqlite3.connect("VOL_HOURS.db")
def fromVolunteers():
conn = sqlite3.connect("VOL_HOURS.db")
with conn:
cur = conn.cursor()
cur.execute("SELECT BOB, DAVE, CAROL, ANDY, CARL, DANNY, CHERYL, CYNTHIA, TARA, SCOTT, ASHLEY, CRYSTAL FROM VOLUNTEERS")
rows = cur.fetchall()
def main():
fromVolunteers()
testOutput = open(FILENAME, "w+")
for row in rows:
vlist = VLIST()
vlist.setBob(row[0])
vlist.setDave(row[1])
vlist.setCarol(row[2])
vlist.setAndy(row[3])
vlist.setCarl(row[4])
vlist.setDanny(row[5])
vlist.setCheryl(row[6])
vlist.setCynthia(row[7])
vlist.setTara(row[8])
vlist.setScott(row[9])
vlist.setAshley(row[10])
vlist.setCrystal(row[11])
vlist.dump_object(testOutput)
testOutput.flush()
testOutput.close()
cur.close()
conn.close()
答案 0 :(得分:4)
implode('</td><td>', $Array1)
implode('</td><td>', $Array2)
implode('</td><td>', $Array3)
猜猜这就是你想要做的......
使用td
代替tr
答案 1 :(得分:2)
如果您愿意,也可以保留数组。但内爆不能以这种方式使用。这也适合你:
$Array1 = array('qualitypoint', 'technologies', 'India','Hey');
$Array2 = array('quality', 'tech', 'Ind','He');
$Array3 = array('q', 't', 'I','H');
echo '<table border = "3px">';
foreach($Array1 as $key => $value){
echo '<tr><td>' . $Array1[$key] .'</td><td>' . $Array2[$key] .'</td><td>' . $Array3[$key] .'</td></tr>';
}
echo '</table>';
答案 2 :(得分:1)
忘掉一切可能破坏第一次机会的内乱。首先重构数组并将它们合并为1个数组。
$Array[1] = array('qualitypoint', 'technologies', 'India','Hey');
$Array[2] = array('quality', 'tech', 'Ind','He');
$Array[3] = array('q', 't', 'I','H');
然后只需做
echo '<table>';
echo '<table>';
for($i=0;$i<=3;$i++)
{
echo "<tr>";
for($j=1;$j<=3;$j++)
{
echo "<td>{$Array[$j][$i]}<td>";
}
echo "</tr>";
}
echo '</table>';
<强>输出强>
table>
<tr>
<td>qualitypoint<td>
<td>quality<td>
<td>q<td>
</tr>
<tr>
<td>technologies<td>
<td>tech<td>
<td>t<td>
</tr>
<tr>
<td>India<td>
<td>Ind<td>
<td>I<td>
</tr>
<tr>
<td>Hey<td>
<td>He<td>
<td>H<td>
</tr>
</table>
提示您可以使用count()
而不用担心硬编码循环的限制。这样,您可以根据需要扩展数据而无需更改代码