Avatar billede traded Nybegynder
23. september 2001 - 21:58 Der er 15 kommentarer og
1 løsning

HASTER PHP PROBLEM

Jeg har et problem, http://www.alljunk.dk kan i ikke hjælpe mig med at ændre i min phpkode så den knækker rækken ved 20 og så rækken fortsætter på næste linje? Koden kommer her:<?
//----  Settings Start ---\\\\
// Image Information
$imageWidth=100;
$imageHeight=100;

// Table Layout
$rows=2;
$cols=4;

//Image path
$hotlib=\"junk/billeder2/\"; // remember to finish with /
$libery=\"billeder2/\"; // remember to finish with /
$liberythumb=\"billeder2_thumb/\"; // remember to finish with /

// Settings Stop----------//

$viewNum=$cols*$rows;
if(!$firstImage){ // so it works if you just enter default.php and show the pictures without having to define the variables in the path
        $firstImage=1;
}
function getImages($firstImage){
    global $viewNum, $imageWidth, $imageHeight,$cols,$libery,$liberythumb, $hotlib;  //insures that the function gets the variables
    $handle=opendir($libery); //opens directory
    while($file=readdir($handle)){ // reads the directory
        $extension=substr($file,-4); // gets the extension of the files
        if(($extension == \".jpg\") || ($extension == \".gif\") || ($extension == \".png\") ){ // checks for image files
            $all[]=$file;  //adds positive results to the archive
        }
    }
    $colscounter=0; // variable that controls the tablebuilding system below
    $firstImage--; // variable that insures that the first image is being showed. Case: It looks best if the links begins with 1 but the array begins with 0
    if(isset($all)){  // if array is set build the table
        print \"<table>\";
        for($i=$firstImage; $i < $firstImage+$viewNum; $i++){
            if($all[$i]){ // checks for rinning dry of imges
                if($i==$firstImage + $colscounter*$cols){ // if true: new row
                    $colscounter++;
                    print \"<tr>\";
                } // add the image
                print \"<td><a href=\'http://www.alljunk.dk/b.htm?http://www.alljunk.dk/\".$hotlib.$libery.\"\".$all[$i].\"\'><img src=\'\".$liberythumb.\"\".$all[$i].\"\' border=\'0\' width=\'$imageWidth\' height=\'$imageHeight\' alt=\'Click to Enlarge\'></a></td>\";
            }
            else{ // stop if no more images
                break;
            }
        }
        print \"</table><br>\";
        $num=count($all);  //number of pictures in actual libery
        makeList($num); // function to make the links list
    }
    else{
        print \"Der var desværre ingen billeder i dette bibliotek<br><a href=\'java script:history.back()\'>Go Back</a>\";
    }
}
function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            print \"$a</a>&nbsp;&nbsp;\";
        }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
        }
    }
}

Avatar billede fireworld Nybegynder
23. september 2001 - 22:11 #1
du laver en tæller ... som tæller en op hver gang løkken kører og så med en if sætning laver du

if ($var==20) { print\"<br>\"; }
Avatar billede traded Nybegynder
23. september 2001 - 22:12 #2
Hvor skal det sættes ind i php scriptet?
Avatar billede traded Nybegynder
23. september 2001 - 22:16 #3
HJÆLP?
Avatar billede lauer Nybegynder
23. september 2001 - 22:21 #4
Vi prøver igen.
function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            print \"$a&nbsp;&nbsp;\";
        }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
        }
        if ($a%20==0) { print=\"<br>\"}
    }
}

Avatar billede traded Nybegynder
24. september 2001 - 14:45 #5
Det virker ikke på den måde machomann har sat koden ind, er der nogen der kan gøre det rigtigt??
Avatar billede traded Nybegynder
24. september 2001 - 14:50 #6
hallo??
Avatar billede lauer Nybegynder
24. september 2001 - 15:03 #7
øhh.. er du sikker på det?
har du indsat den nu?
det er bare
if ($a%20==0) { print=\"<br>\"}
jeg har indsat
Avatar billede lauer Nybegynder
24. september 2001 - 15:12 #8
ups, det er fordi der skal stå
if ($a%20==0) { print (\"<br>\") }
Avatar billede traded Nybegynder
24. september 2001 - 15:45 #9
Det virker stadig ikke?
Avatar billede traded Nybegynder
24. september 2001 - 15:55 #10
Nu virker det .. Delvist .. check http://www.alljunk.dk og se når man klikker på f.eks 3 kommer der til at stå det samme tal to gange, her kommer koden:
Avatar billede traded Nybegynder
24. september 2001 - 15:55 #11
<?
//----  Settings Start ---\\\\
// Image Information
$imageWidth=100;
$imageHeight=100;

// Table Layout
$rows=2;
$cols=4;

//Image path
$hotlib=\"junk/billeder2/\"; // remember to finish with /
$libery=\"billeder2/\"; // remember to finish with /
$liberythumb=\"billeder2_thumb/\"; // remember to finish with /

// Settings Stop----------//

$viewNum=$cols*$rows;
if(!$firstImage){ // so it works if you just enter default.php and show the pictures without having to define the variables in the path
        $firstImage=1;
}
function getImages($firstImage){
    global $viewNum, $imageWidth, $imageHeight,$cols,$libery,$liberythumb, $hotlib;  //insures that the function gets the variables
    $handle=opendir($libery); //opens directory
    while($file=readdir($handle)){ // reads the directory
        $extension=substr($file,-4); // gets the extension of the files
        if(($extension == \".jpg\") || ($extension == \".gif\") || ($extension == \".png\") ){ // checks for image files
            $all[]=$file;  //adds positive results to the archive
        }
    }
    $colscounter=0; // variable that controls the tablebuilding system below
    $firstImage--; // variable that insures that the first image is being showed. Case: It looks best if the links begins with 1 but the array begins with 0
    if(isset($all)){  // if array is set build the table
        print \"<table>\";
        for($i=$firstImage; $i < $firstImage+$viewNum; $i++){
            if($all[$i]){ // checks for rinning dry of imges
                if($i==$firstImage + $colscounter*$cols){ // if true: new row
                    $colscounter++;
                    print \"<tr>\";
                } // add the image
                print \"<td><a href=\'http://www.alljunk.dk/b.htm?http://www.alljunk.dk/\".$hotlib.$libery.\"\".$all[$i].\"\'><img src=\'\".$liberythumb.\"\".$all[$i].\"\' border=\'0\' width=\'$imageWidth\' height=\'$imageHeight\' alt=\'Click to Enlarge\'></a></td>\";
            }
            else{ // stop if no more images
                break;
            }
        }
        print \"</table><br>\";
        $num=count($all);  //number of pictures in actual libery
        makeList($num); // function to make the links list
    }
    else{
        print \"Der var desv&aelig;rre ingen billeder i dette bibliotek<br><a href=\'java script:history.back()\'>Go Back</a>\";
    }
}
function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+2;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page if ($var==23) { print\"<br>\"; }
            print \"$a</a>&nbsp;&nbsp;\";
        } if ($a%20==0) { print (\"<br>\"); }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
      }


}
 
}

?>
Avatar billede lauer Nybegynder
24. september 2001 - 15:58 #12
det er fordi du har sat det forkert ind...
sådan skal den sidste funktion være:

unction makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            print \"$a&nbsp;&nbsp;\";
        }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
        }
        if ($a%20==0) { print (\"<br>\")}
    }
}
Avatar billede lauer Nybegynder
24. september 2001 - 16:07 #13
ups... der manglede lige lidt
function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=0; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            print \"$a&nbsp;&nbsp;\";
        }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
        }
        if ($a%20==0) { print(\"<br>\");}
    }
}

nu skulle det virke
Avatar billede lauer Nybegynder
24. september 2001 - 16:10 #14
hmm, det ser ikke så godt ud med det 0 først...
prøv

function makeList($num){
    global $libery, $firstImage, $viewNum; //insures that the function gets the variables
    $numLinks = $num / $viewNum; // finds the number og links to be maked
    for($a=1; $a < $numLinks;$a++){
            $start=$a*$viewNum+1;  //adds 1 because then the links begins with ex. number 1-10 and 11-20 instead of 0-10 and 10-20
            $finish=$a*$viewNum+$viewNum;
            if($finish>$num){ // insures that the final link returns the right amount of pictures instead of to much
                $finish=$num;
            }
        if(($firstImage >= $start) && ($firstImage < $a * $viewNum+$viewNum)){ // if true: makes no link because you already are on the page
            $print \"$a&nbsp;&nbsp;\";
        }
        else{ // makes the link
            print \"<a href=\'default.php?libery=$libery&firstImage=$start\'>$a</a>&nbsp;&nbsp;\";
        }
        if ($a%20==0) { print(\"<br>\");}
    }
}
Avatar billede traded Nybegynder
24. september 2001 - 16:20 #15
Tak for al hjælpen ;-)
Avatar billede lauer Nybegynder
24. september 2001 - 16:53 #16
det var så lidt... tak for point
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester