Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

loop syntax..

loop syntax

  • Please log in to reply
5 replies to this topic

#1 Whitey

Whitey

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 259 posts

Posted 01 July 2008 - 08:34 PM


$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..
  • 0

#2 Whitey

Whitey

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 259 posts

Posted 02 July 2008 - 12:25 AM

sorry if that made no sense.. here is the full code


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


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

#3 Xav

Xav

    CC Mentor

  • VIP Member
  • PipPipPipPipPipPipPipPip
  • 8356 posts

Posted 02 July 2008 - 09:08 AM

You should never have to print PHP code to the actual PHP document. If you want to call something multiple times, use a loop or something.
  • 0
If you enjoy reading this discussion and are thinking about commenting, why not click here to register and start participating in under a minute?

#4 Whitey

Whitey

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 259 posts

Posted 02 July 2008 - 02:18 PM

Well i do have to.. so..
  • 0

#5 John

John

    CC Mentor

  • Moderator
  • 4450 posts
  • Location:New York, NY

Posted 02 July 2008 - 02:33 PM

I can almost guarantee there is a better way to accomplish this task. Nonetheless, I think this is what you want: PHP: eval - Manual
  • 0

#6 Whitey

Whitey

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 259 posts

Posted 02 July 2008 - 03:10 PM

yes thank you! :)
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download