Foros del Web » Programando para Internet » PHP »

PHP-SQL ayuda por favor...

Estas en el tema de PHP-SQL ayuda por favor... en el foro de PHP en Foros del Web. Hola foreros,necesito ayuda,lo he pedido un par de veces pero nadie me contesta o no me explico bien,o es dificil lo que pido pero algo ...
  #1 (permalink)  
Antiguo 25/11/2009, 11:23
 
Fecha de Ingreso: octubre-2009
Mensajes: 154
Antigüedad: 14 años, 6 meses
Puntos: 0
PHP-SQL ayuda por favor...

Hola foreros,necesito ayuda,lo he pedido un par de veces pero nadie me contesta o no me explico bien,o es dificil lo que pido pero algo falla...jejeje Es un poco largo pero espero encontrar algun alma caritativa

Creo que realmente es sencillo pero llevo 3 dias y no lo soluciono:

Lo unico que tengo que hacer es coger unos valores de una base de datos y sacarlos por pantalla en un template,mi problema es que solo escribo una tabla con los datos del cliente cuando me deberian de salir una por cada uno de ellos,eso no se hacerlo.Como es que en una consulta salen varios?Porque puede haber varias personas con el mismo nombre en la base de datos.La idea es mostrar por pantalla uno a continuacion del otro.
Metes firstname y lastname t lo busca en la base de datos y lo mete en el template..

codigo:



Esta es la funcion que coge los datos de la DB y los meto en el template:




************************************************** *****


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]);




$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");
}

$num_user=(mysql_num_rows($result));
while ($num_user != 0)
{
echo($num_user);
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"]);
}

$num_user--;
}
$tpl->parse(result, "main");
$tpl->FastPrint(result);


}








[/SIZE][/COLOR]


************************************************** *****



este es el template donde meto los datos


*******************************************


<html><head>
<title>show</title>
<link href="templates/style/buttons.css" type=text/css rel=stylesheet>
<link href="templates/style/W3C-REC.css" type=text/css rel=stylesheet>

<script>

function recall(form){
window.location.href = "search_customer.php?id="+document.forms[0].elements['cus_id'].value+"&serv="+document.forms[0].elements['name_service_html'].value;
//alert (document.forms[0].elements['cus_id'].value+"&serv="+document.forms[0].elements['name_service_html'].value);
}
</script>


<body textcolor=white background="images/topBG2.png">
<p align=LEFT>
<form name = "nuevo" action = "{SCRIPT}" method = "POST">
<input type=hidden name=cus_id value='{CUSTOMER}'>
<table width = 535 height="1" bordercolor="#000080" border="0">
<tr>
<td align = left width="33" valign="top" height="40" bgcolor="#000080">
&nbsp;
</td>
<td align = left width="637" valign="top" height="40" bgcolor=darkblue>
<font size="5" color="#FFFFFF" face="Arial Black"><h1>{NAME}</h1></font>
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="1">
</td>
<td align = left width="637" valign="top" height="1">
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="13" bgcolor="#000099">
&nbsp;
</td>
<td align = left width="637" valign="top" height="13" bgcolor="#000099">
<font color="#FFFFFF" face="Arial Black">Company Profile</font>
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="1">
</td>
<td align = left width="637" valign="top" height="1">
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="1">
</td>
<td align = left width="637" valign="top" height="1">
&nbsp;
<table border="1" width="99%">
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif"><B>Company (Project)
Name {COMPANY}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "company_name_html" value="{COMPANY_VALUE}" size = "120" maxlength = "255" tabindex=1 >
</font> </td>
</tr>
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif" ><B> Address {ADDRESS}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "address_html" value="{ADDRESS_VALUE}"size = "120" maxlength = "255"tabindex=2>
</font>
</td>
</tr>
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif"><B>Postcode {POSTCODE}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "postcode_html" value="{POSTCODE_VALUE}"size = "120" maxlength = "255"tabindex=3>
</font>
</td>
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif"><B>Telephone {TEL}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "tel_html" value="{TEL_VALUE}"size = "120" maxlength = "255" tabindex=4>
</font>
</td>
</tr>
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif"><B> Fax {FAX}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "fax_html" value="{FAX_VALUE}" size = "120" maxlength = "255" tabindex=5>
</font>
</td>
</tr>
<tr>
<td width="30%"><font color=black color=white face="Times New Roman, Times, serif"> <B>Country</B> </font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "country_html" value="{COUNTRY_VALUE}" size = "120" maxlength = "255" tabindex=5>
{COUNTRY}
</select>
</td>
</tr>

</table>
<p>&nbsp;
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="13" bgcolor="#000099">
&nbsp;
</td>
<td align = left width="637" valign="top" height="13" bgcolor="#000099">
<font color="#FFFFFF" face="Arial Black">Contact Person</font>
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="1">
</td>
<td align = left width="637" valign="top" height="1">
</td>
</tr>
<tr>
<td align = left width="33" valign="top" height="1">
</td>
<td align = left width="637" valign="top" height="1">
&nbsp;
<table border="1" width="99%">
<tr>
<td width="30%"><font color="black" face="Times New Roman, Times, serif"><B>First
Name {FIRST}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif">
<input type = "text" name = "firstname_html" value="{FIRST_VALUE}" size = "30" maxlength = "50"tabindex=7>
</font>
</td>
</tr>
<tr>
<td width="30%"><font color="black" face="Times New Roman, Times, serif"><B>Last
Name {LAST}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif"><input type = "text" name = "lastname_html" value="{LAST_VALUE}" size = "30" maxlength = "70"tabindex=8>
</font>
</td>
</tr>
<tr>
<td width="30%"><font color="black" face="Times New Roman, Times, serif"><B>E-mail
Address {EMAIL}</B></font></td>
<td width="70%"><font color=white color=white face="Times New Roman, Times, serif">
<input type = "text" name = "email_html" value="{EMAIL_VALUE}" size = "30" maxlength = "70"tabindex=9>
</font>
</td>
</tr>
</table>
<p>&nbsp;
</td>
</tr>
</form>
</body></html>

************************************************** **
  #2 (permalink)  
Antiguo 16/01/2010, 11:06
Avatar de jenusys  
Fecha de Ingreso: diciembre-2008
Ubicación: Ahí mismo.
Mensajes: 216
Antigüedad: 15 años, 4 meses
Puntos: 11
Respuesta: PHP-SQL ayuda por favor...

¿Ya probaste con GROUP BY en SQL y luego hacer una consulta sobre eso?
El asunto es que cada nombre debe tener un ID único (cédula de ciudadanía, número registro, etc.) y en ese caso deberás ordenar ello desde SQL sea alfabéticamente, numéricamente, por fecha, etc.
Luego deberás meter todo ello en "arrays" por nombre que hará que se separen dichos nombres cuando los muestres en los "templates".

Si después de tanto tiempo aún necesitas ayuda yo puedo hacerlo que tuve un problema similar.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:11.