我想创建一个包含3列的表,例如" Number of Follower",代码中描述的$tweetstimeline
值的第二列,以及" $ tweetstimeline_2'的第三列值。
我尝试过使用<tr>
,<td
&gt;和<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";
答案 0 :(得分:1)
尝试基本的html表结构:
<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>";
}
答案 1 :(得分:1)
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>";
尝试以此为出发点,然后根据自己的需要选择“代码”+ varhere +“endcode”。
答案 2 :(得分:1)
我认为您希望它的表结构不正确。尝试这样的事情:
<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:对不起我的英语,我正在学习