ayuda!!!!
hola quiero cargar datos de una bd a un combo box en php con mysql, pero todos mis intentos son fallidos, por favor si alguien podria ayudarme con esto estaria muy agradecido. El ultimo intento al que llegue fue este:
<script language="JavaScript">
function loaddoc()
{
/* similar al script para departamento, pero con un parámetro mas en el id */
cod_doc=document.forms[0].cod_doc.value
/* cargar nuevamente la página, pero ahora con los parámetros cod_dep y cod_pro */
newhtp=(document.URL.indexOf("?")>0)?document.URL.substring(0,document.URL.indexOf("?")):document.URL
newurl=newhtp+"?cod_doc="+cod_doc;
if(cod_doc==0)newurl=newhtp;
window.location.href=newurl;
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>carga combo</title>
</head>
<body>
<h1><strong>Documentos de Caja</strong></h1>
<strong>Documento</strong>
<SELECT name="doc" onchange="loaddoc ()">
<option cod_doc='0' value='0' selected>Adicionar Documento</option>
<?php
$query=mysql_query('SELECT cod_doc, doc FROM doccaja WHERE cod_doc=$cod_doc group by cod_doc, doc;');
//$query=mysql_query('select cod_doc,doc from doccaja');
include "conexion.php";
$bdres=pg_exec($conexion,$query);
$row=0; $rowmax=pg_NumRows($dbres);
if($rowmax>0)
{
while($row<$rowmax)
{
$do=pg_Fetch_Object($dbres,$row);?>
<option value='<?echo($do->cod_doc)?>'
<?if($cod_doc>0 and $cod_doc==$do->cod_doc){?>
selected
<?} else { if($cod_doc>0){
$query1=mysql_query('select cod_doc, doc from doccaja where cod_doc=$cod_doc group by cod_doc, doc;');
$dbres1 = pg_exec($conexion, $query1);
$row1=0; $rowmax1=pg_NumRows($dbres1);
if($rowmax1>0)
{$do1=pg_Fetch_Object($dbres1,$row1);
$cod_doc=$do1->cod_doc;
if ($cod_doc==$do1->cod_doc)
{?>
selected
<?}}}}?>
><?echo($do1->doc)?> </option>
<?$row++;
}
}
include "cerrar_conexion.php";
?>
</SELECT>
</body>
</html>
<script language="JavaScript">
function loaddoc()
{
/* similar al script para departamento, pero con un parámetro mas en el id */
cod_doc=document.forms[0].cod_doc.value
/* cargar nuevamente la página, pero ahora con los parámetros cod_dep y cod_pro */
newhtp=(document.URL.indexOf("?")>0)?document.URL.substring(0,document.URL.indexOf("?")):document.URL
newurl=newhtp+"?cod_doc="+cod_doc;
if(cod_doc==0)newurl=newhtp;
window.location.href=newurl;
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>carga combo</title>
</head>
<body>
<h1><strong>Documentos de Caja</strong></h1>
<strong>Documento</strong>
<SELECT name="doc" onchange="loaddoc ()">
<option cod_doc='0' value='0' selected>Adicionar Documento</option>
<?php
$query=mysql_query('SELECT cod_doc, doc FROM doccaja WHERE cod_doc=$cod_doc group by cod_doc, doc;');
//$query=mysql_query('select cod_doc,doc from doccaja');
include "conexion.php";
$bdres=pg_exec($conexion,$query);
$row=0; $rowmax=pg_NumRows($dbres);
if($rowmax>0)
{
while($row<$rowmax)
{
$do=pg_Fetch_Object($dbres,$row);?>
<option value='<?echo($do->cod_doc)?>'
<?if($cod_doc>0 and $cod_doc==$do->cod_doc){?>
selected
<?} else { if($cod_doc>0){
$query1=mysql_query('select cod_doc, doc from doccaja where cod_doc=$cod_doc group by cod_doc, doc;');
$dbres1 = pg_exec($conexion, $query1);
$row1=0; $rowmax1=pg_NumRows($dbres1);
if($rowmax1>0)
{$do1=pg_Fetch_Object($dbres1,$row1);
$cod_doc=$do1->cod_doc;
if ($cod_doc==$do1->cod_doc)
{?>
selected
<?}}}}?>
><?echo($do1->doc)?> </option>
<?$row++;
}
}
include "cerrar_conexion.php";
?>
</SELECT>
</body>
</html>
