Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_php thread: NIK need a hand to follow your advise


Message #1 by "jorge" <jorge@d...> on Tue, 15 Oct 2002 09:24:51 -0500
Hi Nik
Cant find a way to do this with no loop my code is in spanish explanation in english
thanks

i have the following tables

table 1 company_general_info
holds de company_id_number that is built this way first to digits represente the state,following three digits represents the client
number  last to digits represent te type of company (if this is the corporate = 00 or if its a branch of the corporte is 01,02, 03
etc depend on the number of branches) 

so a typical company_id_number  is 
01(alabama).001(first registered company. 00 (corporate)
and 02.010.01 is alaska company number 10 branch 1
this means that 02.010.00 must exists since is the corporate office must exist before a branch can exist  02.010.01 (010 company
number)
so every company can have as many branches 

in any company_id_number the dot "." is used to separate state . number . type

table 2 contains the address info.

I want to list by state all the branches with their address, group by the state of the corporate order by state,corporate 

SELECT state number , then grab all the company_id_number  only those which are corporate, then look for all the branches of those
corporates gruoped by corporate and order by corporate,branch, then grab the info form table 2 of each branch.display results
Important the corporate state can be diferent from the branches (like a corporation in illinois can have branches any other state).

what i am doing rite now

<?
 echo($tr);
 echo("<td colspan=\"2\" class=\"top\">".$estado.$ftd);
 echo($ftr);
//aqui sacamos las matrizes 
$querya=mysql_query("SELECT DISTINCT numero_de_socio FROM datos_generales WHERE Entidad_Federativa='$estado' AND
Esta_RPT_es='Matriz' ORDER BY numero_de_socio");
while($resultadosa=mysql_fetch_array($querya,MYSQL_ASSOC))
 {
 $numero_de_socioa=$resultadosa["numero_de_socio"];
 //con esto sacamos el consecutivo del socio
 $numeroa=substr($numero_de_socioa,2,5);
 
$query="SELECT DISTINCT numero_de_socio FROM datos_generales WHERE numero_de_socio LIKE '%$numeroa%' AND Esta_RPT_es='Extensión'
ORDER BY numero_de_socio";
if(!($db_query=mysql_query($query))){echo(mysql_error());}
while($resultados=mysql_fetch_array($db_query,MYSQL_ASSOC))
 {
 $numero_de_socio=$resultados["numero_de_socio"];
 //con esto sacamos la terminacion del socio
 $extension_1=substr($numero_de_socio,6,8);
 //con esto sacamos el consecutivo del socio
 $numero=substr($numero_de_socio,2,5);
 //concatenamos el consecutivo del socio con ".00" para sacar la matriz
 $number=$numero."00";

 if($extension_1==".01")
  {
  if(!($queryC=mysql_query("SELECT Ciudad,Nombre_o_Razón_Social FROM datos_generales WHERE numero_de_socio LIKE
'%$number'"))){echo(mysql_error());}
  $resultadosC=mysql_fetch_array($queryC);
  $CiudadM=$resultadosC["Ciudad"];
  $Nombre_o_Razón_Social=$resultadosC["Nombre_o_Razón_Social"];
  echo($tr);
  echo("<td class=\"respuestastablabg\">&nbsp; ".$ftd);
  echo("<td class=\"respuestastablabg\">&nbsp;".$ftd);
  echo($ftr);
  echo($tr);
  echo("<td class=\"respuestastablabg\">Ciudad: ".$ftd);
  echo("<td class=\"respuestastablabg\"><b>".$CiudadM."</b>".$$ftd);
  echo($ftr);
  echo($tr);
  echo("<td class=\"respuestastablabg\">Nombre o Razón Social:".$ftd);
  echo("<td class=\"respuestastablabg\">".$Nombre_o_Razón_Social.$ftd);
  echo($ftr);
  }
  $queryc=mysql_query("SELECT numero_de_socio,Ciudad FROM datos_generales WHERE numero_de_socio = '$numero_de_socio'");
   $n=0;
   while($results=mysql_fetch_array($queryc,MYSQL_ASSOC))
    {
    if($extension_1==".01"){$txt="Extensión (es): ";}else{$txt=" ";}
    $numero_de_socio=$results["numero_de_socio"];
    $Ciudad=$results["Ciudad"];
    echo($tr);
    echo("<td class=\"respuestastablabg\">".$ftd);
    echo($ftr);
    echo($tr);
    echo("<td class=\"respuestastablabg\">".$txt.$ftd);
    echo("<td class=\"respuestastablabg\">".$Ciudad." "."(".$numero_de_socio.")".$ftd);
    echo($ftr);
    $n++;
    }//fin while interno
  }//fin while externo
 }//fin while externo
?>


  Return to Index