Вопрос

I've got the following...

 <a href='Count.php?count=Red'><

but how would i make it so it counts more than one colour?

 <a href='Count.php?count=Red, Green, Blue'><

doesnt work, nor does replacing the , with &&, any ideas?

Here's the PHP code that does the counting:

<?php 
$lineNumber=0; 
$handle = fopen('shapeStorage.txt', 'r'); 
if ($handle) 
    { 
    while (($line = fgets($handle))!== false) 
        { 
        $lines[$lineNumber] = $line; 
        $lineNumber++; 
        } 
    } 
else 
    { 
    echo 'error, error, high voltage';
    } 
for($n=0; $n<sizeof($lines); $n++)
    { 
    if(strstr($lines[$n], $_GET["count"])) $colourCount++; 
    } 
echo '<h2>There are '.$colourCount.' '.$_GET["count"].' shape(s) stored within the site.</h2>'; 
?>
Это было полезно?

Решение

I think this is what you should do:

<a href='Count.php?count=Red-Green-Blue'>

Now in PHP you can split it up using the hyphen like this:

$Colours = explode("-", $_GET["count"]);

Now use the $Colours array in your code.

This is not the solution to your counting algorithm, but it is the answer to your question on how to include multiple colours.

Hope this helps.

Другие советы

Use array syntax for the variable name:

<a href='Count.php?count[]=Red&count[]=Green&count[]=Blue'>

Then on the PHP side:

$colors = $_GET['count'];
print_r($colors);
/* OUTPUTS
Array
(
    [0] => Red
    [1] => Green
    [2] => Blue
)
*/
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top