Como cargo un combo desde una bd mysql?¿

anonynous
24 de Abril del 2004
Hola amigos, de verdad necesito ayuda en este tema, tras muchos intentos, no puedo jalar los datos, muy agradecido por su colaboración. Mi ultimo intento fu el siguiente:

<script language="JavaScript">
function loaddoc()
{
cod_doc=document.forms[0].cod_doc.value
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>


<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>