php - Dynamically create variables in foreach loop and use on another page -
i'm using dynamic template custom made cms. want variables
from 1 php-page and, each created site uses page, want use variables in foreach
to, example display each title.
i have made simple example below explain this:
home.com/gallery/1 home.com/gallery/2 home.com/gallery/3
what get:
gallery 1 gallery 1 gallery 1
what want:
gallery 1 gallery 2 gallery 3
(assuming each page named gallery 1, 2, 3)
gallery.php
<form action=""> <input type="text" name="page_title"> </form> <?php $galleries = array(); $id = intval($_post["id"]); ? foreach ($galleries $id => $gallery) { $title = $_post["page_title"]; } $_session['galleries'] = $galleries; $_session['title'] = $title; ?> <h1><?php echo $title; ?></h1>
page.php:
$galleries = $_session['galleries']; $title = $_session['title']; foreach ($galleries $id => $gallery) { echo $title; echo "<br>"; } ?>
note: because want use variables on multiple pages can't assign form's action specific php-page.
ok, found sollution: page.php:
$galleries = $_session['galleries']; $title = $_session['title']; foreach ($galleries $id => $gallery) { echo $gallery["title"]; //echo line instead of $title echo "<br>"; } ?>
Comments
Post a Comment