Current location: Hot Scripts Forums » Programming Languages » PHP » How do you output PHP on index page.


How do you output PHP on index page.

Reply
  #1 (permalink)  
Old 07-22-06, 01:15 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
How do you output PHP on index page.

Lets say I have a PHP generated in a box on an index page: www.mysite.com/index.php

On this index page, I have some pull downs that lets a visitor select some search parameters for example and that is posted to a file called "select.php". In my select.php file I have an echo line that generates the output, how can I display this output back on the index page in the same fashion that my original page was? I have a working output that just prints on a blank page.
Reply With Quote
  #2 (permalink)  
Old 07-22-06, 03:48 PM
billthecat billthecat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Not sure about all your requirements - maybe you can change this for your needs:

index.php:
PHP Code:

<?php 

session_start
();

if (isset(
$_SESSION["selectmenu"]))
  echo 
"You selected " $_SESSION["selectmenu"] . "!<br />";
else
  echo 
"no selection made yet!<br />";
?>
<h4>My Form</h4> 
<form action="select.php" method="post" name="selection">
<select size="1" name="selectmenu">
<option value="" selected>Select A State</option>
<option value="New York">New York</option>
<option value="California">California</option>
<option value="Florida">Florida</option>
<option value="Rhode Island">Rhode Island</option>
</select>
<input type="submit" value="Submit">
</form>
select.php:
PHP Code:

<?php

session_start
();

echo 
$_POST['selectmenu'];
$_SESSION['selectmenu'] = $_POST['selectmenu'];

?>
<br /><br />
<a href="index.php">Go back</a> to the index page and see the post.

Last edited by nico_swd; 07-22-06 at 03:53 PM. Reason: Please use [php] wrappers when posing PHP code.
Reply With Quote
  #3 (permalink)  
Old 07-23-06, 02:55 PM
billthecat billthecat is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks nico_swd
Reply With Quote
  #4 (permalink)  
Old 07-24-06, 11:36 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks. I'm sorry, here is a better description of what I'm talking about. On my index page I display the date and some "tips of the day" (tip.php-displayed in an iframe) derived from a delimited text file.
PHP Code:

<div align="center"

<?php
   
echo date("<b>F j</b>");
?>
</div>
PHP Code:

<?php //tip.php This displays on the index page in an iframe


$file file('data.txt');
$today getdate();

echo
'<table style="width:400px; height:200px; padding:0px; border:0px"><tr><td>';
foreach (
$file as $line => $data)
{
    list(
$month$day$year$tip) = explode('|'trim($data) );
 
    if (
$today['month'] == $month AND $today['mday'] == $day)   
 {
   
         echo 
'<font face="Times New Roman" size="2px">'$tip .'</font>';
         echo 
"<p>";
   
   }
}
echo
'</td></tr></table>';
?>
The iframe:
Code:
<iframe name="iFrame1" width=425 height=225 src="tip.php" scrolling="auto" frameborder="0"></iframe>
After viewing that, the view would then be able to select any day of the year and go to that result:
Code:
<form action="select.php" method="POST">

<select name="month">
   <option value="January">January
            ***   thru ****
   <option value="December">December
</select>

<select name="day">
   <option value="1">1
         ***   thru ***
   <option value="31">31
</select>

   <input type="submit" name="Get Tip" value="Get Tip"/>
</form>
That form submission then posts to select.php which is here:
PHP Code:

<?php  // from select.php


$monthselect $_POST['month'];
$dayselect $_POST['day'];

$file file('data.txt');

echo
'<table style="width:400px; height:200px; padding:0px; border:0px"><tr><td>';
foreach (
$file as $line => $data)
{
    list(
$month$day$year$tip) = explode('|'trim($data) );
 
    if (
$monthselect == $month AND $dayselect == $day)   
 {
   
         echo 
'<font face="Times New Roman" size="2px">'$tip .'</font>';
         echo 
"<p>";
   
   }
}
echo
'</td></tr></table>';
?>
My problem is that this output is printed on a blank page in the upperleft corner. I want to display it as I do the original tip.php file that was displayed on my index page. I would prefer if this output was displayed on a regenerated index page. Any suggestions as to what code I would use?

Thanks in advance!
Reply With Quote
  #5 (permalink)  
Old 07-25-06, 08:57 PM
9999 9999 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 86
Thanks: 0
Thanked 0 Times in 0 Posts
Does this make sense?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot include google search in a web page with php liviusbr PHP 1 05-19-06 09:36 AM
Classified Ads skipper23 Perl 3 11-22-05 02:22 AM
How to Make my Php output write static Html files cebuy PHP 1 02-04-05 05:52 AM
creating static page with php ivan PHP 1 06-26-04 09:08 AM
Classified Ads skipper23 Perl 2 12-30-03 03:43 AM


All times are GMT -5. The time now is 07:22 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.