문제

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