Jump to content

I need help with syntax


whiteboikyle

Recommended Posts

$result = $config->query("SELECT * FROM pages");
	for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)
	{
		$page = mysql_result($result, $i, "pages");
		elseif($function == "$page")
		{
		include("functions/".$page.".php");
		}
	}

 

i need it to add an elseif to the actual if equation.. so pretty much when they add a function it does it all for them..

Link to comment
https://forums.phpfreaks.com/topic/112878-i-need-help-with-syntax/
Share on other sites

okay i am making something where people can add a function.. Well each function is viewed by a $_GET['view'] well... For the function to work it has to be allowed through the view.php page.. So i want it to add an elseif{ the include function } and loop it through..

 

here is the full page..

 

 

<?php
include("header.php");
session_start();
$myusername = $_SESSION['myusername'];
$function = $_GET['function'];
if(isset($myusername)){
if(isset($function)){
	if($function == ""){
	header("location: main.php");
	}
	$result = $config->query("SELECT * FROM pages");
	for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)
	{
		$page = mysql_result($result, $i, "pages");
		elseif($function == "$page")
		{
		include("functions/".$page.".php");
		}
	}
	else{
	echo("<center> You entered an invalid function line! </center>");
	}
}else{
header_sent("main.php");
}
}
else{
header_sent("main.php");
}
include("footer.php");
?>

What i am trying to say.. its kinda hard to explain.. but like here is an example..

 

lets say i have a table that had a column called name..

 

well

 

what the name is, its a name of a php file..

 

and lets say you wanted to loop out the php files.. using php laungage..

 

so instead of doing something with a loop and echoing something..

 

i wan it to loop and print some php code.. but not just display it.. i want it to run that php code..

 

 

so what i want this code to do is

 

loop the actual php code

 

so

 

$page = banip

 

would echo this.. (but not really echo.. just show the code)

elseif($function == "banip")

{

include("functions/banip.php");

}

instead of:

 

...
for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1) {
$page = mysql_result($result, $i, "pages");

elseif($function == "$page") {
include("functions/".$page.".php");
}
}
...

 

try:

 

...
for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1) {
$page = mysql_result($result, $i, "pages");

if($function == "$page") {
include("functions/".$page.".php");
break;
}
}
...

 

if that is what you are aiming. :)

Look at my last 1.. i am trying to do alot of elseif's.. but i need it to ECHO the php so to speak.. but not really echo.. It needs to print the actual PHP code through a loop into the PHP! not into the website!

 

EDIT:

 

 

okay well here is another way to explain it.. i dono how else to..

 

if you do an if statement with some elseifs  and else at the end liek so

 

if(){

}

elseif(){

}

elseif(){

}

elseif(){

}

else{

}

 

well.. the 3 elseif i want to make them generated.. but i just dono how to make it print php code to the php document..

if($function == ""){

header("location: main.php");

}

$result = $config->query("SELECT * FROM pages");

for ($i = 0; $i < mysql_num_rows($result); $i = $i + 1)

{

$page = mysql_result($result, $i, "pages");

elseif($function == "$page")

{

include("functions/".$page.".php");

}

}

else{

echo("<center> You entered an invalid function line! </center>");

}

 

see the if statement and the else at the end..

 

 

i want the elseif statements in the middle to be generated!

like so it looks like

 

if(){

}

elseif(){

}

elseif(){

}

elseif(){

}

else(){

}

 

of course there will be way more elseif statments then that but i am trying to explain this to you guys :)

 

 

Now i am pretty sure there is a way to do this!

 

I know the way i wrote it wont work... lol thats why i am asking for help..

 

 

now if someone could help me i would be of so much appreciation !

lol i am surprised to see no 1 found that.. lol

 

@whiteboikyle

 

You cannot blame the people trying to help you then just disclosed with that because of a poorly structured question in the first place. No offense here, though am also new here, I don't find your recent posts quite polite unless a certain ego was touched.

 

I just understood your question at your third to the last post in this thread.

that's a nice find though :).

 

peace!  ;)

No, dont take it rude at all.. I know i cant put my questions together.. I am a bad write. I usually explain stuff by pictures.. But, its a lack of creativity haha..

 

but, what i ment was i posted that on another forum with like less people then here, (300 members) and they found it first post.

Thats what i ment by that..

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.