Jump to content

[SOLVED] stuck again... just a variable to call files


ashess

Recommended Posts

hi guys. I made quite some headway since last I came here.

unfortunately, I am stuck again.

what I want to do now is call different text files with my side buttons.

calling a textfile worked fine, but putting in a variable in its place is giving me difficulties.

I tough I had it figure, but now I'm just making it worse and worse, and just confusing myself.

 

so if anyone knows what I'm doing wrong pls help :)

<?php


// Point to the folder containing the images. Relative path without trailing slash!
$imgfolder    =    "storyboard";
$dir = 'storyboard'; 

$filecount = 0; 
$d = dir($dir); 

while ($f = $d->read()) 
{  if(($f!= ".") && ($f!= "..")) 
{  if(!is_dir($f)) $filecount++;  } 
} 



?>
<html>
<head>
<title>Project Redz</title>
    <link rel="stylesheet" type="text/css" href="style.css">  
</head>
<body>
<div id="mainwindow">
<div id="sidediv">
<!-- first part of the troublesome part -->
<a onClick="textfile='news.txt;'"><div id="sidebutton">NEWS</div></a>
<!-- end of first part -->
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="lastbutton">text</div>
</div>

<div id="logodiv"><img src="webimages/logo.png"></div>
<div id="namediv"><img src="webimages/name.png"></div>
<div id="bannerdiv"></div>

<div id="stripwindow"> 	<img id='plaatje' src="'.$imgfolder.'/'.$img.'" border="1"> 	</div>

<div id="buttonsdiv"> 

<input type="image" src="webimages/firstbutton.png" id="first" class="button" width="120px"  onClick="showFirstPicture();" >

<input type="image" src="webimages/previousbutton.png" id="previous" class="button" width="120px" onClick="showPreviousPicture();" > 

<input type="image" src="webimages/nextbutton.png" id="next" class="button" width="120px" onClick="showNextPicture();" >

<input type="image" src="webimages/lastbutton.png" id="last" class="button" width="120px" onClick="showLastPicture();" > 
</div>

//2nd part troublesome part
<div id="textdiv">
<?php include ',textfile'; ?>
</div>
<div id="imagecountdiv">

<?php echo 'there are currently ',$filecount,' strippages up.'; ?>
</div>
</body>


<script type="text/javascript">
window.onload=function()
{
    var textfile="text.txt";
    
}

//2nd part troublesome part ends here

var imageCount=0;

window.onload=function()
{
    imageCount=1;
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}

function showNextPicture()
{ 

if (imageCount < '<?php echo $filecount ?>') {
    imageCount++;}
else { imageCount=1;
}
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
function showPreviousPicture()
{
if (imageCount > 1 ) {
    imageCount--;
}
else {imageCount= '<?php echo $filecount ?>';
}
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
function showFirstPicture()
{

    imageCount=1;
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}

function showLastPicture()
{    
    imageCount='<?php echo $filecount ?>';
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
</script>


</html>

Some things I noticed.

 

First, rewrite this line:

<a onClick="textfile='news.txt;'"><div id="sidebutton">NEWS</div></a>

as this:

<div id="sidebutton"><a onClick="textfile='news.txt;'">NEWS</a></div>

anchor tags are inline elements, divs are block elements.  Inline elements shouldn't contain block elements.

 

Next, you have some unescaped PHP in your HTML:

   <div id="stripwindow">    <img id='plaatje' src="'.$imgfolder.'/'.$img.'" border="1">    </div>

should be:

   <div id="stripwindow">    <img id='plaatje' src="<?php echo "$imgfolder/$img" ?>" border="1">    </div>

 

If you just want links that load different textfiles, it would probably be easier to make the links link to the same page, with a GET variable to specify which text file to load.

 

Here is an example of how you could do it:

<?php

// Point to the folder containing the images. Relative path without trailing slash!
$imgfolder = "storyboard";
$dir = 'storyboard'; 

$filecount = 0; 
$d = dir($dir); 

while ($f = $d->read()) {  
if ($f != "." && $f != "..") {  
	if (!is_dir($f)) {
		$filecount++;
	}  
} 
}

$textfile = '';

switch ($_GET['textfile']) {
case 'textfile1':
	$textfile = 'textfile1.txt';
	break;
case 'textfile2':
	$textfile = 'textfile2.txt';
	break
default:
	$textfile = 'default.txt';
}


?>
<html>
<head>
<title>Project Redz</title>
    <link rel="stylesheet" type="text/css" href="style.css"> 
</head>
<body>
<div id="mainwindow">
<div id="sidediv">
<div id="sidebutton"><a href="">default</a></div>
<div id="sidebutton"><a href="?textfile=textfile1">textfile 1</a></div>
<div id="sidebutton"><a href="?textfile=textfile2">textfile 2</a></div>
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="sidebutton">text</div>
<div id="lastbutton">text</div>
</div>

<div id="logodiv"><img src="webimages/logo.png"></div>
<div id="namediv"><img src="webimages/name.png"></div>
   <div id="bannerdiv"></div>

   <div id="stripwindow">    <img id='plaatje' src="<?php echo "$imgfolder/$img" ?>" border="1">    </div>

   <div id="buttonsdiv">

   <input type="image" src="webimages/firstbutton.png" id="first" class="button" width="120px"  onClick="showFirstPicture();" >

   <input type="image" src="webimages/previousbutton.png" id="previous" class="button" width="120px" onClick="showPreviousPicture();" >

   <input type="image" src="webimages/nextbutton.png" id="next" class="button" width="120px" onClick="showNextPicture();" >

   <input type="image" src="webimages/lastbutton.png" id="last" class="button" width="120px" onClick="showLastPicture();" >
   </div>

//2nd part troublesome part
<div id="textdiv">
<?php include $textfile ?>
</div>
<div id="imagecountdiv">

<?php echo 'there are currently ',$filecount,' strippages up.'; ?>
</div>
<script type="text/javascript">
window.onload=function()
{
    var textfile="text.txt";
   
}

//2nd part troublesome part ends here

var imageCount=0;

window.onload=function()
{
    imageCount=1;
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}

function showNextPicture()
{

if (imageCount < '<?php echo $filecount ?>') {
    imageCount++;}
else { imageCount=1;
}
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
function showPreviousPicture()
{
if (imageCount > 1 ) {
    imageCount--;
}
else {imageCount= '<?php echo $filecount ?>';
}
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
function showFirstPicture()
{

    imageCount=1;
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}

function showLastPicture()
{   
    imageCount='<?php echo $filecount ?>';
    var fileName="storyboard/image"+imageCount+".jpg";
    document.getElementById('plaatje').src=fileName;

}
</script>
</body>
</html>

 

 

 

 

hello fly; thanks for taking the time to help me!

I tried the code you gave, but I get a parse error on line 27.

that's the line with the default; but with my limited knowledge of php I cant see anything wrong with it.

 

syntax error, unexpected T_DEFAULT in C:\Domains\ashess.nl\wwwroot\projectZ\index.php on line 27

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.