almost.
it isn't working yet. when i click in processadores it takes forever to load the page and then it gives an error, PAGE NOT FOUND try to refresh bla, bla, bla.
i think it has something to do with the first part, the connection, you see, i use a function inside the same script to call another function that connects to the database,
i'll try and be has clear as i can, here's the whole script that contains the functions:
<?php
// ficheiro com as configurações da ligação á base de dados
require("config.inc.php");
// define a classe como extensão de ligação á base de dados e define a variavel dessa ligação
class IEProcessadores extends BDMySQL {
var $bd;
// chama a função de ligação á base de dados
function IEProcessadores() {
global $NOME_BD, $NOME_SERVIDOR;
$this->bd = new BDMySQL();
$this->bd->ligarBD($NOME_BD, "", "", $NOME_SERVIDOR);
}
// função que desenha o cabeçalho da tabela com os resultados da interrogação
function cabecalhoProcessadores() {
echo "<table width=\"100%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" bgcolor=\"#999999\"><tr bgcolor=\"#b6b7cb\"><td><b><font color=\"#FFFFFF\">Cod.</font></b></td><td><b><font color=\"#FFFFFF\">Categoria</font></b></td><td><b><font color=\"#FFFFFF\">Marca</font></b></td><td><b><font color=\"#FFFFFF\">Modelo</font></b></td><td><b><font color=\"#FFFFFF\">Preço</font></b></td><td><b><font color=\"#FFFFFF\">Disp.</font></b></td></tr>";
}
// função que mostra os items de uma certa categoria existentes em produtos
function listaProcessadores($categoria) {
/* you could put these following variables in a seperate file and include them on the page. That's how I normally do it, I only changed it to look like this for the example */
$server = "localhost";
$username = "";
$password = "";
$database = "inforever";
$table = "produtos";
// Connect To MySQL Server
@mysql_connect($server, $username, $password) or die("Couldn't Connect to Database");
// Select Database
@mysql_select_db($database) or die("Couldn't Select Database");
// set number of results to display per page
$pagelimit = "10";
// run query (change yourtable to the name of your table)
$strSQL = mysql_query("SELECT * FROM produtos WHERE categoria='Processador' OR categoria='Cooler'");
// count number of matches
$totalrows = mysql_num_rows($strSQL);
// determine how many pages there will be by using ceil() and dividing total rows by pagelimit
$pagenums = ceil ($totalrows/$pagelimit);
// if no value for page, page = 1
if ($page==''){
$page='1';
}
// create a start value
$start = ($page-1) * $pagelimit;
// blank matches found
echo "<b>" . $totalrows . " matches found</b><br>\n";
// Showing Results 1 to 1 (or if you're page limit were 5) 1 to 5, etc.
$starting_no = $start + 1;
if ($totalrows - $start < $pagelimit) {
$end_count = $totalrows;
} elseif ($totalrows - $start >= $pagelimit) {
$end_count = $start + $pagelimit;
}
echo "Results $starting_no to $end_count shown.<br>\n";
// create dynamic next, previous, and page links
/* lets say you're set to show 5 results per page and your script comes out with 7 results.
this will allow your script to say next2 if you're on the first page and previous5 if you're on the second page. */
if ($totalrows - $end_count > $pagelimit) {
$var2 = $pagelimit;
} elseif ($totalrows - $end_count <= $pagelimit) {
$var2 = $totalrows - $end_count;
}
$space = " ";
// previous link
if ($page>1) {
echo "« <a href='" . $PHP_SELF . "?page=".($page-1)."' class=main>Previous" . $space . $pagelimit . "</a>" . $space . $space . "";
}
// dynamic page number links
for ($i=1; $i<=$pagenums; $i++) {
if ($i!=$page) {
echo " <a href='" . $PHP_SELF . "?page=$i' class=main>$i</a>";
}
else {
echo " <b class='red'>$i</b>";
}
}
// next link
if ($page<$pagenums) {
echo "" . $space . $space . $space . $space . " <a href='" . $PHP_SELF . "?page=".($page+1)."' class=main>Next " . $var2 . "</a> »";
}
$strSQL2 = mysql_query("SELECT * FROM produtos WHERE categoria='Processador' OR categoria='Cooler' LIMIT $start,$pagelimit");
echo "<table>"; // I didn't see this tag anywhere in your function, so you may want to specify the table attributes
echo "<tr bgcolor=\"#FFFFFF\">";
$n=0;
while(mysql_fetch_row($strSQL2)) {
echo "<td bgcolor=\"#FFFFFF\">".mysql_result($strSQL2, $n, "cod")."</b></td><td bgcolor=\"#FFFFFF\">".mysql_result($rs, $n, "categoria")."</td><td bgcolor=\"#FFFFFF\"><a href=\"index.php?pagina=marca&marca=".mysql_result($rs, $n, "marca")."\">".mysql_result($rs, $n, "marca")."</td><td bgcolor=\"#FFFFFF\"><a href=\"index.php?pagina=produto&modelo=".mysql_result($rs, $n, "modelo")."&cod=".mysql_result($rs, $n, "cod")."&preco=".mysql_result($rs, $n, "preco")."\">".mysql_result($rs, $n, "modelo")."</td><td bgcolor=\"#FFFFFF\">".mysql_result($rs, $n, "preco")."<font color=\"#006699\">€</font></td><td bgcolor=\"#FFFFFF\">".mysql_result($rs, $n, "situacao")."<br></td>";
echo "</tr>";
$n++;
}
echo "</table>";
}
// função que fecha a ligação á base de dados
function endIEProcessadores() {
$this->bd->fecharBD();
}
}
?>
config.inc.php sets the server name, database, username and password and BDMySQL.class.php makes the proper connection.
do you think you can figure out where's the problem.
thank you very much in advance.