Jump to content

Multiple form mysql query and pages numbering


Eiffelmtl

Recommended Posts

Hello everyone,

I'm not not an expert in php and this is why I write on this forum.

I have a page with two search form (one per category, the other by age group) and I display my results from a query with pagination.

All good until I move from one page to another: as soon as I change the page I lose my list of results and my page does not show anything other than my form.

I did a print_r of my sessions and the launch of my page I have:

Array()

Once my form send I got for exemple:

Array ( [categorie] => 4 )

But when I go to another page of my result, I go back to:

Array()

Can you help me or at least tell me how to fix the problem?

Par Age <img src="../images/check_mark.png" width="50" onclick="MM_changeProp('age','','display','block','DIV');MM_changeProp('cat','','display','none','DIV')"/>
Par catégorie <img src="../images/check_mark.png" width="50" onclick="MM_changeProp('age','','display','none','DIV');MM_changeProp('cat','','display','block','DIV')" />
<div id="age" style="display:none"><form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validateForm()">
<select name="age" id="age">
<option name="ageid" value="1">1</option>
<option name="ageid" value="2">2</option>
<option name="ageid" value="3">3</option>
<option name="ageid" value="4">4</option>
<option name="ageid" value="5">5</option>
<option name="ageid" value="6">6</option>
</select>
<input name="" type="submit" />

</form></div>
<div id="cat" style="display:none">
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" onsubmit="return validateForm()">
<select name="categorie">
<?php


$fp = fopen($_SERVER["DOCUMENT_ROOT"]."/frimousse/Categorie.csv", 'r');
// Headrow
$head = fgetcsv($fp, 4096, ';', '"');

// Rows
while($column = fgetcsv($fp, 4096, ';', '"'))
{
$column = array_combine($head, $column);

?>

<option name="categorieNom" value="<?php echo $column['IdCategorie']?>"><?php echo $column['Nom']?></option>
<?php
}

?>
</select>
<input name="" type="submit" />
</form>
</div>
<?php
session_start ();
if (isset($_POST['categorie']) ) { $_SESSION['categorie'] = $_POST['categorie']; }
if (isset($_POST['age']) ) { $_SESSION['age'] = $_POST['age']; }
include('config.php');
include ('pagination.php');
$per_page = 6;
if (isset($_SESSION['categorie'])) {
$result = mysql_query("SELECT * FROM csvdata where IdCategorie={$_SESSION['categorie']}");
}
if (isset($_SESSION['age'])) {
$result = mysql_query("SELECT * FROM csvdata where AgeVise={$_SESSION['age']}");
}

$total_results = mysql_num_rows($result);
$total_pages = ceil($total_results / $per_page);
if (isset($_GET['page'])) {
$show_page = $_GET['page']; //current page
if ($show_page > 0 && $show_page <= $total_pages) {
$start = ($show_page - 0) * $per_page;
$end = $start + $per_page;
} else {
$start = 0;
$end = $per_page;
}
} else {
$start = 0;
$end = $per_page;
}
// display pagination
$page = intval($_GET['page']);
$tpages=$total_pages;
if ($page <= 0)
$page = 1;
$reload = $_SERVER['PHP_SELF'] . "?tpages=" . $tpages;


for ($i = $start; $i < $end; $i++) {

if ($i == $total_results) {
break;
}
if (mysql_result($result, $i, 'IdCategorie') == "1") {
$cat = "Jeu de motricité";
} elseif (mysql_result($result, $i, 'IdCategorie') == "2") {
$cat = "Jeu d'habileté/rapidité";
} elseif (mysql_result($result, $i, 'IdCategorie') == "3") {
$cat = "Jeu sensoriel";
} elseif (mysql_result($result, $i, 'IdCategorie') == "4") {
$cat = "Jeu de rôles";
} elseif (mysql_result($result, $i, 'IdCategorie') =="5") {
$cat = "Jeu de hasard";
} elseif (mysql_result($result, $i, 'IdCategorie') == "6") {
$cat = "Jeu de construction/assemblage";
} elseif (mysql_result($result, $i, 'IdCategorie') == "7") {
$cat = "Jeu de créativité/artistique";
} elseif (mysql_result($result, $i, 'IdCategorie') == "8") {
$cat = "Jeu de stratégie/réflexion";
} elseif (mysql_result($result, $i, 'IdCategorie') == "9") {
$cat = "Jeu de vocabulaire";
} elseif (mysql_result($result, $i, 'IdCategorie') == "10") {
$cat = "Jeu mathématique";
} elseif (mysql_result($result, $i, 'IdCategorie') == "11") {
$cat = "Jeu d'apprentissage/connaissance";
} elseif (mysql_result($result, $i, 'IdCategorie') == "12") {
$cat = "Jeu de mémoire";
} elseif (mysql_result($result, $i, 'IdCategorie') == "13") {
$cat = "Jeu de plein air";
} elseif (mysql_result($result, $i, 'IdCategorie') == "14") {
$cat = "Livre avec dessins seulement";
} elseif (mysql_result($result, $i, 'IdCategorie') == "15") {
$cat = "Livre avec textes et dessins";
} elseif (mysql_result($result, $i, 'IdCategorie') == "16") {
$cat = "Livre avec textes seulement";
} elseif (mysql_result($result, $i, 'IdCategorie') == "17") {
$cat = "Livre de bricolages";
} elseif (mysql_result($result, $i, 'IdCategorie') == "18") {
$cat = "Livre destiné aux parents";
} elseif (mysql_result($result, $i, 'IdCategorie') == "19") {
$cat = "Cassette vidéo - Dessins animés";
} elseif (mysql_result($result, $i, 'IdCategorie') == "20") {
$cat = "Cassette vidéo - Film";
} elseif (mysql_result($result, $i, 'IdCategorie') == "21") {
$cat = "Cassette audio";
} elseif (mysql_result($result, $i, 'IdCategorie') == "22") {
$cat = "CD-Rom audio";
} elseif (mysql_result($result, $i, 'IdCategorie') == "23") {
$cat = "CD-Rom informatique";
} else {

}
echo "<div style='float:left;width:150px;padding-left:10px;padding-right:10px;height:200px;padding-bottom:50px;vertical-align:top'>";
$IdPhoto = mysql_result($result, $i, 'IdPhoto');

if (empty($IdPhoto))
{
?>
<div style="margin-top:5px;height:100px"><img src="<?php $_SERVER['DOCUMENT_ROOT'];?>/frimousse/dataimg/not-found.jpg" width="120px"></div><br />
<?php
} else {
?>
<div style="margin-top:5px;height:100px"><img src="<?php $_SERVER['DOCUMENT_ROOT'];?>/frimousse/dataimg/i<? echo $IdPhoto ?>.jpg" width="120px" style="padding-bottom:10px"></div><br />

<?php
}
$Titre = utf8_encode(mysql_result($result, $i, 'Titre'));
// echo out the contents of each row into a table
echo '<div style="margin-top:5px;height:35px">' . $Titre . '</div><br />';
echo '<div style="margin-top:-15px;height:20px">' . $cat . '</div><br />';
echo '<div style="margin-top:5px">' . mysql_result($result, $i, 'AgeVise') . '</div><br /></div>';
}
// close table>
echo "<div style='clear:both'></div>";
echo '<div class="pagination"><ul>';
if ($total_pages > 1) {
echo paginate($reload, $show_page, $total_pages);
}
echo "</ul></div>";
// pagination

?>

Thank you very much

Link to comment
Share on other sites

I see session_start() buried in your code...long after you've already output stuff. It must come before any output. It must come before output because session variable uses a session cookie. cookie must be sent in the response headers. If you output something before starting the session, headers are already sent and cookie cannot be sent. If you have your error settings set to display warnings, you should see a "warning: headers already sent" error message output from this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.