Categoria nu ramane selectata la clic pe link

Discutii despre script-uri si coduri PHP-MySQL, precum si lucru cu XML in PHP.
sagap
Mesaje:12

Categoria nu ramane selectata la clic pe link

Salut,

Am si eu un script de afisare date din DB in functie de categorie iar rezultatele sunt paginate la un nr de 150. Atunci cand selectez o categorie datele sunt afisate, iar cand dau click pe link-ul pentru urmatoarea pagina, categoria nu mai ramane selectata, iar rezultatele nu mai sunt afisate.Nu pot sa imi dau seama de unde este problema asa ca o sa pun tot scriptul ce contine PHP:

Cod: Selectaţi tot

<?php

include 'config.php';

$conn = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$conn) {
  echo 'Conectare nereusita la MySQL'; 
  exit;
}

if (!mysql_select_db($dbname, $conn)) {
  echo 'Baza de date nu a putut fi selectata deoarece : '. mysql_error();
  exit;
}

$sql = "SET NAMES 'utf8'";
mysql_query($sql, $conn);

?>

<form method="post" name="myform">
<select name="category" onchange="myform.submit()">
<option value="">Select a category</option>
<?php
$sql = "SELECT * FROM category";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
    while ($row = mysql_fetch_assoc($result)) {
		if(!empty($_POST['category']) AND $_POST['category']==$row["cat_id"])
		$select="selected='selected'";
		else
		$select = '';
        echo '<option value="'.$row["cat_id"].'"   '.$select.' >'.$row["name"].'</option>';
    }
}
?>
</select>

<?php

$sql = "SELECT COUNT(*) FROM `date`";  
$result = mysql_query($sql, $conn) or trigger_error(E_USER_ERROR);  
$r = mysql_fetch_row($result);  
$numrows = $r[0];  

$rowsperpage = 150;  

$totalpages = ceil($numrows / $rowsperpage);
 
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {  

  $currentpage = (int) $_GET['currentpage'];  
} else {  

  $currentpage = 1;  
}
 
if ($currentpage > $totalpages) {  

  $currentpage = $totalpages;  
} 

if ($currentpage < 1) {  

  $currentpage = 1;  
} 
 
$offset = ($currentpage - 1) * $rowsperpage;  

if(!empty($_POST['category'])) {
$category_id = $_POST['category'];
$time = date("Ymd");
$sql = "SELECT date.id, date.url FROM date INNER JOIN video_cat ON date.id = video_cat.id WHERE cat_id = '".$category_id."' ORDER BY RAND('$time') LIMIT $offset, $rowsperpage ";
$result = mysql_query($sql, $conn) or trigger_error(E_USER_ERROR);
$re_out ='';
$i =0;

//if(mysql_num_rows($result) > 0)
//{
    while ($row = mysql_fetch_array($result)) {
		  $id[] = $row['id'];
 		  $url[] = $row['url'];
 		  //$embed_url[] = $row['embed_url'];
 		  //$title[] = $row['title'];
		  //$duration[] = $row['duration'];
 		  // $date_added[] = $row['date_added'];
 		  //$thumbs[] = $row['thumbs'];		  
		  
	  $re_out .='<option value="'.$row["id"].'">'.$row["url"].'</option>';
 	 $i++;
 	 if(($i%2)==0) $re_out .='<br>';
    }

echo $re_out;
}
//}
mysql_close();

$range = 3;


if ($currentpage > 1) {  
  echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> &nbsp; ";  
  $prevpage = $currentpage - 1;  
  echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> &nbsp;";  
} 
 
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {  
  if (($x > 0) && ($x <= $totalpages)) {  
	 if ($x == $currentpage) {  
		echo " [<b>$x</b>] ";  
	 } else {  
	echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";  
	 }  
  }
}

  $nextpage = $currentpage + 1;  
  echo "&nbsp; <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";  
  echo " &nbsp; <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";  

?>

</form>

MarPlo Mesaje:4343
Salut
La clic pe link se deschide doar adresa link-ului, cu datele de tip $_GET din el. Nu se trimite form-ul; deci nu e trimisa nici o valoare $_POST (nu e nici un $_POST['category']) prin care verifici si pui datele din categoria selectata.

Subiecte similare