PHP - 最简单的方法吗?

时间:2015-07-03 03:35:57

标签: php mysql pdo

我正在使用PDO在MySQL中查看一个名为seasons的列,但是如何根据它包含的内容来检查季节和回声的数量,例如,假设它是3,它会将所有这些输出到一个回声:

<a href="season 1">Season 1</a>
<a href="season 2">Season 2</a>
<a href="season 3">Season 3</a>

但是,如果它检查了其他一行并且该行的季节包含5,我会需要它回应:

<a href="season 1">Season 1</a>
<a href="season 2">Season 2</a>
<a href="season 3">Season 3</a>
<a href="season 4">Season 4</a>
<a href="season 5">Season 5</a>

这一切都是在一个文件index.php中完成的,它对load的主要依赖性是一个名为?name =的参数,基本上该名称决定了要执行所有这些检查的行。

我该怎么做?

更新

<a href=".$dl.$dl720p1.$ref.">Season 1</a>
<a href=".$dl.$dl720p2.$ref.">Season 2</a>
<a href=".$dl.$dl720p3.$ref.">Season 3</a>
<a href=".$dl.$dl720p4.$ref.">Season 4</a>

更新

$seasons = 1;

while (isset(${'dl720p' . $seasons})) $seasons++;

for ($i = 1; $i < $seasons; $i++)
    $download =  '<a download class="download-torrent button-green-download-big" onclick="window.open(this.href,\'_blank\');return false;" target="_blank" href="' .$dl . ${'dl720p' . $i} . $ref. '"><span class="icon-in"></span>Season ' . $i . '</a>' . "\n";

1 个答案:

答案 0 :(得分:5)

所以你根据有多少链接输出链接?试试这个:

<?php

$dl720p1 = 'one';
$dl720p2 = 'two';
$dl720p3 = 'three';
$dl720p4 = 'four';
$dl720p5 = 'five';

$seasons = 6;

$dl = 'a';
$ref = 'b';

$download = '';

for ($i = 1; $i <= $seasons; $i++)
    $download .= '<a href="' .$dl . ${'dl720p' . $i} . $ref. '">Season ' . $i . '</a>' . "\n";

echo $download;

Output

<a href="aoneb">Season 1</a>
<a href="atwob">Season 2</a>
<a href="athreeb">Season 3</a>
<a href="afourb">Season 4</a>
<a href="afiveb">Season 5</a>