Jump to content

Loop problem


gaya
 Share

Recommended Posts

for($i=0; $i<6;$i++){if($var[$i]==$str){echo "$str".$var[$i];$strfirstlettercaps = strtolower($str);$var1=$strfirstlettercaps.".php";require_once $var1; }else{$strfirstlettercaps="";$var1=fopen("$strfirstlettercaps".".php","x+");echo "<img src='../uc1.jpg'>";} 

The loop is checking for both if and else condition. I dont know why.please anyone tell me what i'm doing wrong here.

Link to comment
Share on other sites

In some cases, $var[$i] is equal to $str while in others it isn't. What exactly are you doing with that fopen() statement? You're setting $strfirstlettercaps to an empty string and then asking it to open a file called ".php"

Link to comment
Share on other sites

Ya i just want to create a new empty php file like "empty.php". I did it. Now i'm trying to do,by creating that php file, i am trying to show some image.Is that possible.please tell me

Edited by gaya
Link to comment
Share on other sites

hmm... im not quite into this, but tell me if im wrong, should the IMG echo not be (outside) the for if/else statement?...unless its the plan... but not sure, still having trouble understanding that kind of stuff when its coming to the part of loops and if/else statements......

Edited by rootKID
Link to comment
Share on other sites

Ya i just want to create a new empty php file like "empty.php". I did it.
I don't think you're understanding. Look at these two lines: $strfirstlettercaps="";$var1=fopen("$strfirstlettercaps".".php","x+"); The first line sets $strfirstlettercaps to be empty, and then the second line creates a file with that as the filename. The filename of the new file is ".php". It's not "empty.php", it's just ".php" because you just set $strfirstlettercaps to be an empty string.
Now i'm trying to do,by creating that php file, i am trying to show some image.
I don't know what you're asking, how does the file relate to the image?
Link to comment
Share on other sites

In the first mentioned code i simply use the if condition alone. Where i'm creating a new type,i included the code as

 $qtname1="$qtname";	   $var1=fopen("$qtname1".".php","x+");$stringData = "<img src='../uc1.jpg'/>";fwrite($var1, $stringData);fclose($var1);

In the above code $qtname is the name what i am entering newly to the database,and open the created file name included image using file write. ie)$qtname=a.php.

Link to comment
Share on other sites

I'm doing a code for creating question bank for all subjects. I've dont the coding for 6different question type,like fillup,choose etc.In future, if any more new question type is added by admin,the page should not be viewed empty. Just it should show an imge like page is under construction.so i'm trying to create a empty php file and the img code sholud be written in that php file using fopen() & fwrite(). This is what i'm trying to do.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...