PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Nov 06, 2005 12:16 pm
Okay..Here's the deal.. I want to dynamically generate a switch statement;) Reason why is because I'm trying to think of a way to completely automate my webpage creation and all;)
here's what I got...
Code: Select all
$sql="SELECT * FROM case WHERE switch='content'";
$query=mysql_query($sql);
switch ($content)
{
while ($test=mysql_fetch_object($query))
{
case "".$test->cases."":
include("".$test->includes."");
break;
}
default:
include ("main.php");
break;
}
and in my database...
Code: Select all
switch cases includes
content ct ct.php
content c c.php
content phpt phpt.php
content php php.php
content me me.php
content site site.php
content resume resume.php
content resume2 resume2.php
needless to say once I run the script I get an error.. to be exact..
Code: Select all
Parse error: parse error, unexpected T_WHILE, expecting T_CASE or T_DEFAULT or '}' in /home/esitemai/public_html/index.php on line 65
any one care to speculate?
Last edited by
Charles256 on Sun Nov 06, 2005 1:14 pm, edited 1 time in total.
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Nov 06, 2005 1:14 pm
and here is what I came up with...
the main page...
Code: Select all
if (!isset($_REQUEST['content']))
{
$content="BOO";
}
else
{
$content=$_REQUEST['content'];
}
$sql="SELECT * FROM cases WHERE switches='content'";
$query=mysql_query($sql);
while ($test=mysql_fetch_object($query))
{
ifswitch("$content","$test->cases","$test->includes");
}
and my lovely little function...
Code: Select all
function ifswitch($content,$cases,$includes)
{
if($content==$cases)
{
include("$includes");
}
}
granted it's a bunch of if statements but it allows for me to theoretically completely automate page creation..we'll see..
Last edited by
Charles256 on Sun Nov 06, 2005 1:29 pm, edited 1 time in total.
foobar
Forum Regular
Posts: 613 Joined: Wed Sep 28, 2005 10:08 am
Post
by foobar » Sun Nov 06, 2005 1:16 pm
Charles256
DevNet Resident
Posts: 1375 Joined: Fri Sep 16, 2005 9:06 pm
Post
by Charles256 » Sun Nov 06, 2005 1:22 pm
i wanted to avoid the eval statement :-/ and I did thank ya very much;)
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sun Nov 06, 2005 5:23 pm
there's no reason for eval() or the odd if function you came up with that I can see..
Code: Select all
if (!isset($_REQUEST['content']))
{
$content="BOO";
}
else
{
$content=$_REQUEST['content'];
}
$sql="SELECT * FROM cases WHERE switches='content'";
$query=mysql_query($sql);
$acceptancePool = array();
while ($test=mysql_fetch_assoc($query))
{
$acceptancePool[$test['includes']] = $test['cases'];
}
if(($key = array_search($content,$acceptancePool)) === false) {
$key = 'BOO.php';
}
if(is_readable($key)) {
include($key);
}