Author Topic: Help with small get if statment  (Read 3787 times)

0 Members and 1 Guest are viewing this topic.

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Help with small get if statment
« on: March 12, 2010, 01:01:12 AM »
Hey guys am trying to create a small site that using the following code:
Code: [Select]
<?php
/* Grab Page id */
if (!isset($_GET['id'])) {
$id $_GET['id'];
} else {
$id $_GET['id'];
}

/* Load Content */
include("content/".$id.".php");
?>

What am trying to do is if the url is index.php?id=about  it will grab the about.php file and display it. This works great until you just open up index.php were it gives you an error saying:
Notice: Undefined index: id in C:\wamp\www\smallsite\index.php  on line 22
Warning: include(content/.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\smallsite\index.php  on line 27

This is because no ?id= is specified. Any ideas how I can fix this plus add a error page so if neither exist it goes to like a 404 page?

I think it's something like this but I can't get it:
Code: [Select]
<?php
/* Grab Page id */
if (!isset($_GET['id'])) {
$id $_GET['id'];
} elseif(
$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"] == "index.php") {
include("content/index.php");
} else {
$id $_GET['id'];
} else {
echo '404 Error';
}

/* Load Content */
include("content/".$id.".php");
?>


Any help would be great.
-FireDart
« Last Edit: March 12, 2010, 01:04:25 AM by FireDart »

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #1 on: March 12, 2010, 01:19:56 PM »
what does your include("content/index.php"); look like?


I used to send e-mails
 
$data1 = mysql_query("SELECT id FROM pp_files") or die(mysql_error());
while($info1 = mysql_fetch_array( $data1 ))
{
 
$id1 = $info1['id'];
}
« Last Edit: March 12, 2010, 01:34:49 PM by winracer »
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #2 on: March 12, 2010, 09:04:13 PM »
index.php
Code: [Select]
<?php
/* Display Template */
$smarty->display('index.tpl');
?>



index.tpl
Code: [Select]
{{include file="header.tpl"}}
Index
{{include file="footer.tpl"}}

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #3 on: March 13, 2010, 01:15:50 AM »
are you using this in PHPDirector ? I will play around with it and see what I can find
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #4 on: March 13, 2010, 01:24:12 AM »
Yes/No. I was going to try it with PHPDirector but decide I would first try with solo PHP.

I am using smarty if this why your guessing. Just changed the tags "{{" & "}}".

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #5 on: March 13, 2010, 01:36:38 AM »
cool I will paly around with it. I have a question you might can help me with, I will post code later
I am codeing a change password and can get it to get the users longed name.
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #6 on: March 14, 2010, 04:03:24 AM »
Firedart,

you still need help on this?
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #7 on: March 14, 2010, 04:49:24 AM »
Still looking for a solution, I just may E-Mail Jeffery Way at NetTuts+ requesting a video tut on this issue.

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #8 on: March 19, 2010, 01:54:56 AM »
Got it!
Code: [Select]
/* Grab Content */
if (isset($_GET['id'])) {
$id = $_GET['id'];
} else {
$id = "index";
}

/* Load Content */
include("content/".$id.".php");

This just means if no ?id= or ?id=value is present load the index. The main problem thought is not error page  :(

Looking for a solution

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #9 on: March 19, 2010, 08:04:23 PM »
Anyone know what to do a multilevel php get statment?

Such as: index.php?id=media&m=[# goes here]
or
Such as: index.php?id=profile&u=[# goes here]


Got it working, just need to display the info from the MySql when the value for &m= is equal to a media/profile.
« Last Edit: March 19, 2010, 08:26:30 PM by FireDart »

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #10 on: March 20, 2010, 01:35:50 AM »
great, and you going to share :)
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #11 on: March 20, 2010, 01:45:13 AM »
Yah I will share the script, am still having problems with grabing the media info when I select the url:
index.php?id=media&m=1 or index.php?id=media&m=2 etc....



Also nifty Smarty.net tip I found, on the "{include file="header.tpl"}" if you add "title='name of page here'" then have the smarty tag "{$title}" in the title it will display the text you input.

Example:
{include file="header.tpl" title=Home Page}

In header.tpl:
Code: [Select]
<title>{$title}</title>
It will display:
Code: [Select]
<title>Home Page</title>

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #12 on: March 20, 2010, 01:55:56 AM »
Not sure what am doing wrong, am trying to get the the media to display, my media.php
Code: [Select]
<?php
/*
********************
PHPDirector - Media
********************
*/
/* Grab Media ID */
if(isset($_GET['m'])) {
$mediaid $_GET['m'];
} else {
$error "Media not found";
}

/* Assign Error */
$smarty->assign('media_error''$error');


/* Grab Media */
if(isset($mediaid) && is_numeric($mediaid)){
$id mysql_real_escape_string($mediaid);
$result mysql_query("SELECT * FROM phpdir_media WHERE id=$id AND `approved` = '1' LIMIT 1") or die(mysql_error());  
} else{
$result mysql_query("select * from phpdir_media WHERE approved='1' AND rejected='0' order by rand() LIMIT 1") or die(mysql_error());  
}

/* Display Result */
while ($row mysql_fetch_assoc($result)) {
 
$media[] = $row;
 
$smarty->assign('file'$row['file']);
$smarty->assign('vidtype'$row['video_type']);
}





/* Display Template */
$smarty->display('media.tpl');
?>


Am i not assigning my smarty tags correctly?
Code: [Select]
/* Display Result */
while ($row = mysql_fetch_assoc($result)) {
    $media[] = $row;
    $smarty->assign('file', $row['file']);
   $smarty->assign('vidtype', $row['video_type']);
}

I currently only need the file row so I can input the youtube video id dynamically.

media.tpl
Code: [Select]
{{include file="header.tpl" title=Media}}
<h1>Media</h1>
{{include file="players.tpl"}}
{{include file="footer.tpl"}}

player.tpl:
Code: [Select]
{{if $vidtype eq "YouTube"}}
<!--[if !IE]> -->
<object type="application/x-shockwave-flash" style="width:450px; height:366px;" data="http://www.youtube.com/v/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}&amp;autoplay=1">
<param name="movie" value="http://www.youtube.com/v/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}&amp;autoplay=1" />
</object>
<!-- <![endif]-->

<!--[if IE]>
<object width="425" height="344">
<param name="movie" value="http://www.youtube.com/v/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}&amp;autoplay=1" />
<embed src="http://www.youtube.com/v/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}&amp;autoplay=1" type="application/x-shockwave-flash" width="425" height="344" />
</object>
<![endif]-->

{{elseif $vidtype eq "GoogleVideo"}}
   <embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId={{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}" flashvars=""> </embed>

{{elseif $vidtype eq "dailymotion"}}
   <div><object width="425" height="335"><param name="movie" value="http://www.dailymotion.com/swf/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}"></param><param name="allowfullscreen" value="true"></param><embed src="http://www.dailymotion.com/swf/{{if $media[media].file eq ""}}{{$videoid}}{{else}}{{$media[media].file}}{{/if}}" type="application/x-shockwave-flash" width="425" height="334" allowfullscreen="true"></embed></object></div>
   
{{else}}
{{$media_error|default:"Media not found"}}
{{/if}}




Also I changed the code so instead of using the default smarty tags "{}" I use "{{}}".

Offline winracer

  • Development Team
  • Pro Member
  • *******
  • Posts: 446
  • Karma: 3
    • View Profile
    • helpmewithperl.com
  • Script Version: 1.0+
Re: Help with small get if statment
« Reply #13 on: March 20, 2010, 02:08:16 AM »
Yah I will share the script, am still having problems with grabing the media info when I select the url:
index.php?id=media&m=1 or index.php?id=media&m=2 etc....



Also nifty Smarty.net tip I found, on the "{include file="header.tpl"}" if you add "title='name of page here'" then have the smarty tag "{$title}" in the title it will display the text you input.

Example:
{include file="header.tpl" title=Home Page}

In header.tpl:
Code: [Select]
<title>{$title}</title>
It will display:
Code: [Select]
<title>Home Page</title>

cool thanks.


I am learning more about smarty every day like in the .tpl
this is part of the display video/post by user :)

<center>Click On Each Link Below To View Other Post By {$user5}
{foreach from=$userresult key=myid item=item}
<li><a href="media-{$item.id}">Post {$item.id}<a></li>
 
{/foreach}

</center>


and php file

$result=mysql_query("SELECT id FROM pp_files where submitter = '$user5'");
 


 $counter = 1;   
        $userresult = array();
        do
        {
               while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
                {
                        $userresult[$counter] = array("id"=>$row['id']);
                        $counter = $counter + 1;
                }
        }
        while (! EOF);

$smarty->assign('userresult', $userresult);
winracer
myfunnypets.com
helpmewithperl.com
coosavalleyclassifieds.com
brownlows.net
myphpforum.com

Offline FireDart

  • Project Leader
  • Pro Member
  • *****
  • Posts: 406
  • Karma: 4
    • View Profile
    • FireDart
Re: Help with small get if statment
« Reply #14 on: March 20, 2010, 02:12:57 AM »
That is helpful thanks.