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
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");
?>

Link to comment
Share on other sites

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");

}

Link to comment
Share on other sites

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. :)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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 !

Link to comment
Share on other sites

If you indent your code logically we might be able to read it. Look at your last post, your fist if is closed on the third line, hence there is no room for an elseif.

 

I think you need to get back to basics.

Link to comment
Share on other sites

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

 

Maybe the reason nobody found it is because of the distinct lack of detail in your request. If you can't piece together a question, how are we meant to provide an answer?

Link to comment
Share on other sites

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!  ;)

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.