Respuesta: Mostrar informacion de BD la funcion saca la informacion de la base de datos y luego la escribo con otra funcion en un archivo template que es ql que se muestra,el problema es que si hay dos,solo m es escribe un cuadro con la informacion de un cliente,pero yo quiero que salgan los dos,puede haber dos personas con el mismo nombre.pongo el codigo para ver si lo dejo mas claro:
Este es el main:
session_start();
require_once('class.FastTemplate.php4');
require_once('connection_data.php');
require_once('mysql_func.php');
require_once('insertFunc.php');
require_once('search_func.php');
$table_id = R4decrypt($HTTP_POST_VARS['custolist']);
$id_crypt = $HTTP_POST_VARS['custolist'];
//------------------------------ main -------------------------------------
$ret = 2;
//get the information via http post
$search = $HTTP_POST_VARS[Search];
//initialize the fast templates
$tpl = new FastTemplate(".");
$tpl->define(array("main" => "templates/search.tpl"));
$tpl->assign(SCRIPT,$PHP_SELF);
$tpl->assign(NAME, "Search");
//$tpl->assign(Debug,$table_id.":".$id_crypt);
country_select($tpl,$country_html);
company_select($tpl,$companylist_html);
getSelectValue_3($tpl,"search_customer.php",$lette r);
//-------------------------------------------------------------------------------------------------------------------
if ($search == 'Search')
{
$ret = checkValues_Search($tpl,$table_id);
//he puesto aqui $table_id porq sino no se de donde la coge en el otro lado.
}
else
{
resetValues_search($tpl);//---esto si lo desactivas tb funciona xo cuando seleccionas un pais lueg se keda puesto
// esta se supone que borra los valres que has metido (insertFunc.php)
}
if ($ret==0)
{
//insert values in show_search3.tpl
Insertion_Search("templates/show_search3.htm");
//reset values
reset($HTTP_POST_VARS);
$ret = 2;
$insert = "";
exit();
}
else if ($ret==1)
{
$tpl->assign(NAME, "<FONT COLOR=\"red\"> Warning </FONT> <FONT COLOR=\"red\"> Search </FONT> ");
}
$tpl->assign(BUTTONS, '<input class="buttons" type = "submit" value="Search" color=blue name="Search">');
//display the template
$tpl->parse(result, "main");
$tpl->FastPrint(result);
?>
y aqui estan las funciones: function Insertion_Search($scriptname)
{
global $HTTP_POST_VARS;
global $MySQL;
$firstname = $HTTP_POST_VARS[firstname_html];
$lastname = $HTTP_POST_VARS[lastname_html];
$table_id = R4decrypt($HTTP_POST_VARS[custolist]);
$cantidaduser = 2;
$tpl = new FastTemplate(".");
$tpl->define(array("main" => $scriptname));
if ((empty($firstname)) and (empty($lastname)) and ($table_id>0))
{
$sql = "select cus_id, firstname, surname, company, address, postcode, tel, mobile_phone, fax, email, country
from customers
where (cus_id = '$table_id')";
$result = send_sql($MySQL->db1, $sql);
}
elseif (empty($lastname))
{
$sql = "select firstname, surname, company, address, postcode, tel, mobile_phone, fax, email, country
from customers
where (firstname = '$firstname')";
$result = send_sql($MySQL->db1, $sql);
}
elseif (empty($firstname))
{
$sql = "select firstname, surname, company, address, postcode, tel, mobile_phone, fax, email, country
from customers
where (surname = '$lastname')";
$result = send_sql($MySQL->db1, $sql);
}
else
{
$sql = "select firstname, surname, company, address, postcode, tel, mobile_phone, fax, email, country
from customers
where (firstname = '$firstname') and (surname = '$lastname')";
$result = send_sql($MySQL->db1, $sql);
}
//if($row=mysql_fetch_array($result))
if (!$result)
{
die ("Database Error");
}
//show all the customers,maybe can be more than one whit the same name
while ($cantidaduser!=0)
{
while ($value=mysql_fetch_array($result))
{
$tpl->assign(FIRST_VALUE, $value["firstname"]);
$tpl->assign(LAST_VALUE, $value["surname"]);
$tpl->assign(COMPANY_VALUE, $value["company"]);
$tpl->assign(ADDRESS_VALUE, $value["address"]);
$tpl->assign(POSTCODE_VALUE, $value["postcode"]);
$tpl->assign(TEL_VALUE, $value["tel"]);
$tpl->assign(MOBILE_PHONE_VALUE, $value["mobile_phone"]);
$tpl->assign(FAX_VALUE, $value["fax"]);
$tpl->assign(EMAIL_VALUE, $value["email"]);
$tpl->assign(COUNTRY_VALUE, $value["country"]);
}
$cantidaduser--;
}
$tpl->parse(result, "main");
$tpl->FastPrint(result);
}
//************************************************** *************************************
// This function check if values introduce by the user are correct and not empty and call to the function:
// check*****istingFirstnameAndLastNameSearch function checkValues_Search(&$tpl,$table_id)
//he annadido aqui table_id como variable k paso porq sino no se de donde la saca esta funcion..
{
global $HTTP_POST_VARS;
//reset values to the fasttemplate
$tpl->assign(FIRST, "");
$tpl->assign(LAST, "");
$tpl->assign(COUNTRY_1, "");
$tpl->assign(COMPANYLIST, "");
country_select($tpl,$country);
company_select($tpl,$companylist);
$search="";
//post variables set?
if (!isset($HTTP_POST_VARS["firstname_html"]) || !isset($HTTP_POST_VARS["lastname_html"]))
{
echo "Post variables not set";
}
$firstname = trim($HTTP_POST_VARS["firstname_html"]);
$lastname = trim($HTTP_POST_VARS["lastname_html"]);
$country = $HTTP_POST_VARS["country_html"];
$companylist = $HTTP_POST_VARS["companylist_html"];
///////write values to the FastTemplate
$tpl->assign(FIRST_VALUE, $firstname);
$tpl->assign(LAST_VALUE, $lastname);
country_select($tpl,$country);
company_select($tpl,$companylist);
//$tpl->assign(NAME, "<FONT COLOR=\"red\">Error </FONT>");
//////check for empty values
if ( (empty($firstname)) and (empty($lastname)) and ($table_id < 0))
{
//echo $table_id;
//echo('hola');
$tpl->assign(FIRST, '<FONT SIZE="3" COLOR="red"> **missing Customer Firstname and Lastname** </FONT>');
echo $table_id;
return(1);
}
/*if (empty($lastname))
{
$tpl->assign(LAST, '<FONT SIZE="3" COLOR="red"> **missing Customer Lastname** </FONT>');
return(1);
}*/
//To check if the name is in the DB
if (check*****istingFirstnameAndLastNameSearch ($tpl,$firstname,$lastname,$table_id))
{
return (1);
}
}
//************************************************** *****************************************
// This function check if a customer introducing by the user is already in the DB and moreover check if there are 2 or mor
// customers stored whit the same name in the DB.If only there are 1 the information about this customer is showned us.
// If there are more than 1,that reapeated customer should be appears in the customer list. function check*****istingFirstnameAndLastNameSearch (&$tpl,$firstname,$lastname,$table_id)
{
global $MySQL;
if ((empty($firstname)) and (empty($lastname)) and ($table_id > 0))
{
$sql = "select cus_id from customers where cus_id = '$table_id'";
$result = send_sql($MySQL->db1, $sql);
}
elseif (empty($firstname))
{
$sql = "select surname from customers where surname = '$lastname'";
$result = send_sql($MySQL->db1, $sql);
}
elseif (empty($lastname))
{
$sql = "select firstname from customers where firstname = '$firstname'";
$result = send_sql($MySQL->db1, $sql);
}
else
{
$sql = "select firstname from customers where firstname = '$firstname' AND surname = '$lastname'";
$result = send_sql($MySQL->db1, $sql);
}
if (!$result) //Here we check if the customer is in the database,and in this case if it is repeated.
{
die('database error');
}
if ((mysql_num_rows($result) != 0)) //there are matches
{
if ((mysql_num_rows($result) == 1))
{
return(0); //go to Main in search_customer.php which call to Insertion_Search and show information
}
else //There are more than one matches
{
//Here list the name when there are more than one customer whit the same name.
$num_same_user=(mysql_num_rows($result));
//echo "there are   $num_same_user   users whit this name <br>";
/*while($num_same_user!=0)
{
echo($num_same_user);
$num_same_user--;
}
return(1);*/
echo($num_same_user);
return(0);
}
}
else // Customer is not already at the database.
{
$tpl->assign(FIRST, '<FONT SIZE="3" COLOR="red">** Customer not already in DB **</FONT>');
return (1);
}
}
En rojo estan las funciones, el usuario mete los nombres y da a buscar,primero esta funcion function checkValues_Search comprueba que hay valores introducidos y despues llama a la funcion check*****istingFirstnameAndLastNameSearch que busca cuantos valores hay iguales al introducido,si hay se sale,si hay uno llama a function Insertion_Search que es la que inserta los valores en el archivo template y si hay varios ahi es cuando no se que hacer..
yo creo que tiene que ser algo a la hora de inserta los valores en el template.
Lo unico que me tiene que salir es en vez de un cuadro con la informacion de un cliente,tantos cuadros,uno a continuacion del otro con todos los clientes con ese nombre. |