在 table PHP 中显示文本
Displaying text in table PHP
我想创建一个包含 3 列的 table,其中一列用于值的名称,例如 "Number of Follower",第二列用于代码中描述的 $tweetstimeline
值,第三列为“$tweetstimeline_2”值。
我尝试过使用 <tr>
、<td
> 和 <th>
,但是我对此还是个新手,没有得到正确的结果。有人可以提供解决方案吗?
echo "Number of Followers: ".$tweetstimeline[0]->user->followers_count;
echo "<br />\n";
echo "Name of Twitter Page: ".$tweetstimeline[0]->user->name;
echo "<br />\n";
echo "Location: ".$tweetstimeline[0]->user->location;
echo "<br />\n";
echo "Description: ".$tweetstimeline[0]->user->description;
echo "<br />\n";
echo "URL: ".$tweetstimeline[0]->user->url;
echo "<br />\n";
echo "Number of Friends: ".$tweetstimeline[0]->user->friends_count;
echo "<br />\n";
echo "Number of Statuses: ".$tweetstimeline[0]->user->statuses_count;
echo "<br />\n";
echo "<br />\n";
echo "Number of Followers: ".$tweetstimeline_2[0]->user->followers_count;
echo "<br />\n";
echo "Name of Twitter Page: ".$tweetstimeline_2[0]->user->name;
echo "<br />\n";
echo "Location: ".$tweetstimeline_2[0]->user->location;
echo "<br />\n";
echo "Description: ".$tweetstimeline_2[0]->user->description;
echo "<br />\n";
echo "URL: ".$tweetstimeline_2[0]->user->url;
echo "<br />\n";
echo "Number of Friends: ".$tweetstimeline_2[0]->user->friends_count;
echo "<br />\n";
echo "Number of Statuses: ".$tweetstimeline_2[0]->user->statuses_count;
echo "<br />\n";
echo "<br />\n";
尝试基本的htmltable结构:
<table>
<thead>
<tr>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>content 1</td>
<td>content 2</td>
<td>content 3</td>
</tr>
</tbody>
</table>
在 <tbody>
之后,您可以使用 foreach
遍历所有元素。
foreach ($tweetstimeline as $row) {
echo "<tr>";
echo "<td>{$row->user->name}</td>";
echo "<td>{$row->user->location}</td>";
echo "<td>{$row->user->description}</td>";
echo "</tr>";
}
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td>Number of Followers</td>";
echo "<td>$tweetstimeline</td> ";
echo "<td>$tweetstimeline_2</td>";
echo "</tr>";
echo "<tr>";
echo "<td>100</td>";
echo "<td>wtfgoeshere?</td>";
echo "<td>and here?</td>";
echo "</tr>";
echo "<tr>";
echo "<td>30</td>";
echo "<td>wtfgoeshere</td> ";
echo "<td>and here?</td>";
echo "</tr>";
echo "<tr>";
echo "<td>60</td>";
echo "<td>wtfgoeshere</td> ";
echo "<td>and here?</td>";
echo "</tr>";
echo "</table>";
尝试像这样的东西作为起点,然后按照你觉得合适的方式做 "code" + varhere + "endcode" 。
我认为您想要的 table 结构不正确。尝试这样的事情:
<table>
<thead>
<tr>
<td># Tweetstimeline</td>
<td>Number of followers</td>
<td>Name</td>
<td>Location</td>
<td>Description</td>
<td>Url</td>
<td>Friends Count</td>
<td>Status count</td>
</tr>
</thead>
<tbody>
<?php
$rows = 2; //number of rows goes here
for($i = 0 ; $i < $rows ; $i++){
//output html row:
echo "<tr>";
echo "<td>$i</td>";
echo "<td> $tweetstimeline[$i]->user->followers_count </td>";
echo "<td> $tweetstimeline[$i]->user->name </td>";
echo "<td> $tweetstimeline[$i]->user->location </td>";
echo "<td> $tweetstimeline[$i]->user->description </td>";
echo "<td> $tweetstimeline[$i]->user->url </td>";
echo "<td> $tweetstimeline[$i]->user->friends_count </td>";
echo "<td> $tweetstimeline[$i]->user->statuses_count </td>";
echo "</tr>";
}
?>
</tbody>
</table>
PS: 对不起我的英语,我正在学习
我想创建一个包含 3 列的 table,其中一列用于值的名称,例如 "Number of Follower",第二列用于代码中描述的 $tweetstimeline
值,第三列为“$tweetstimeline_2”值。
我尝试过使用 <tr>
、<td
> 和 <th>
,但是我对此还是个新手,没有得到正确的结果。有人可以提供解决方案吗?
echo "Number of Followers: ".$tweetstimeline[0]->user->followers_count;
echo "<br />\n";
echo "Name of Twitter Page: ".$tweetstimeline[0]->user->name;
echo "<br />\n";
echo "Location: ".$tweetstimeline[0]->user->location;
echo "<br />\n";
echo "Description: ".$tweetstimeline[0]->user->description;
echo "<br />\n";
echo "URL: ".$tweetstimeline[0]->user->url;
echo "<br />\n";
echo "Number of Friends: ".$tweetstimeline[0]->user->friends_count;
echo "<br />\n";
echo "Number of Statuses: ".$tweetstimeline[0]->user->statuses_count;
echo "<br />\n";
echo "<br />\n";
echo "Number of Followers: ".$tweetstimeline_2[0]->user->followers_count;
echo "<br />\n";
echo "Name of Twitter Page: ".$tweetstimeline_2[0]->user->name;
echo "<br />\n";
echo "Location: ".$tweetstimeline_2[0]->user->location;
echo "<br />\n";
echo "Description: ".$tweetstimeline_2[0]->user->description;
echo "<br />\n";
echo "URL: ".$tweetstimeline_2[0]->user->url;
echo "<br />\n";
echo "Number of Friends: ".$tweetstimeline_2[0]->user->friends_count;
echo "<br />\n";
echo "Number of Statuses: ".$tweetstimeline_2[0]->user->statuses_count;
echo "<br />\n";
echo "<br />\n";
尝试基本的htmltable结构:
<table>
<thead>
<tr>
<th>header 1</th>
<th>header 2</th>
<th>header 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>content 1</td>
<td>content 2</td>
<td>content 3</td>
</tr>
</tbody>
</table>
在 <tbody>
之后,您可以使用 foreach
遍历所有元素。
foreach ($tweetstimeline as $row) {
echo "<tr>";
echo "<td>{$row->user->name}</td>";
echo "<td>{$row->user->location}</td>";
echo "<td>{$row->user->description}</td>";
echo "</tr>";
}
echo "<table style='width:100%'>";
echo "<tr>";
echo "<td>Number of Followers</td>";
echo "<td>$tweetstimeline</td> ";
echo "<td>$tweetstimeline_2</td>";
echo "</tr>";
echo "<tr>";
echo "<td>100</td>";
echo "<td>wtfgoeshere?</td>";
echo "<td>and here?</td>";
echo "</tr>";
echo "<tr>";
echo "<td>30</td>";
echo "<td>wtfgoeshere</td> ";
echo "<td>and here?</td>";
echo "</tr>";
echo "<tr>";
echo "<td>60</td>";
echo "<td>wtfgoeshere</td> ";
echo "<td>and here?</td>";
echo "</tr>";
echo "</table>";
尝试像这样的东西作为起点,然后按照你觉得合适的方式做 "code" + varhere + "endcode" 。
我认为您想要的 table 结构不正确。尝试这样的事情:
<table>
<thead>
<tr>
<td># Tweetstimeline</td>
<td>Number of followers</td>
<td>Name</td>
<td>Location</td>
<td>Description</td>
<td>Url</td>
<td>Friends Count</td>
<td>Status count</td>
</tr>
</thead>
<tbody>
<?php
$rows = 2; //number of rows goes here
for($i = 0 ; $i < $rows ; $i++){
//output html row:
echo "<tr>";
echo "<td>$i</td>";
echo "<td> $tweetstimeline[$i]->user->followers_count </td>";
echo "<td> $tweetstimeline[$i]->user->name </td>";
echo "<td> $tweetstimeline[$i]->user->location </td>";
echo "<td> $tweetstimeline[$i]->user->description </td>";
echo "<td> $tweetstimeline[$i]->user->url </td>";
echo "<td> $tweetstimeline[$i]->user->friends_count </td>";
echo "<td> $tweetstimeline[$i]->user->statuses_count </td>";
echo "</tr>";
}
?>
</tbody>
</table>
PS: 对不起我的英语,我正在学习