Kyubeh2435436
Kyubeh2435436

Reputation: 123

PHP - Easiest Way Of Doing This?

Im checking a column called seasons in MySQL using PDO but how would I go around to check how much is in seasons and echo depending on what it contains for example, lets say it is 3, it would output all of this in one echo:

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

But what if it checks some other row and that row's season contains 5 I would need it to echo:

<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>

This is all being done in one file index.php and its main dependancy to load is a parameter called ?name= basically the name determines what row to do all this checking on.

How would I do this?

Update:

<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>

Update:

$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";

Upvotes: 3

Views: 58

Answers (1)

Dave Chen
Dave Chen

Reputation: 10975

So you're outputting the links based on how many there are? Try this:

<?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>

Upvotes: 5

Related Questions