Reputation: 1889
Hello guys i have the following PHP script:
if(isset($_POST['add_slider']))
{
echo '<div class="sliderz">';
$images = mysql_query("SELECT * FROM store");
while($row = mysql_fetch_assoc($images))
{
echo '<ul class="connectedSortable">';
echo '<li>';
echo "<img class='ui-state-default' src=".$row['image'].">";
echo '</li>';
echo '</ul>';
}
echo '</div>';
}
and the html looks like this:
<form action="admin.php" method="POST">
<input type="submit" value="Add new slider!" name='add_slider'>
</form>
How can i acciev the same thing but save it into $_SESSION :-?
Upvotes: 0
Views: 718
Reputation: 2724
if(isset($_POST['add_slider']))
{
$output = '<div class="sliderz">';
$images = mysql_query("SELECT * FROM store");
while($row = mysql_fetch_assoc($images))
{
$output .= '<ul class="connectedSortable">';
$output .= '<li>';
$output .= "<img class='ui-state-default' src=".$row['image'].">";
$output .= '</li>';
$output .= '</ul>';
}
$output .= '</div>';
$_SESSION['yourKey'] = $output;
}
this will store the div
as a string in $_SESSION
array with yourKey
as a key
when you need that just do
echo $_SEESION['yourKey'];
also dont forget to start your session with session_start();
or else it will give errors.
Upvotes: 1
Reputation: 197
try this,
<?php
if(isset($_POST['add_slider']))
{
$arr = array(); //the array will hold the html element
$arr[] = '<div class="sliderz">';
$images = mysql_query("SELECT * FROM store");
while($row = mysql_fetch_assoc($images))
{
$arr[] = '<ul class="connectedSortable">';
$arr[] = '<li>';
$arr[] = "<img class='ui-state-default' src=".$row['image'].">";
$arr[] = '</li>';
$arr[] = '</ul>';
}
$arr[] = '</div>';
$_SESSION['your_session'] = implode("",$arr); // the array content will be gluedd together to form a your div with contents inside it
}
?>
Upvotes: 1