Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

populate textfields based on selection from a dropdown 1

Status
Not open for further replies.

new2everything

IS-IT--Management
Sep 17, 2009
6
GB
Hi, my question is based on the thread under this URL:
The above thread shows how to populate a single textfield from a pull down menu. What I'd like to do is to have hidden fields with each select option and have their values transferred to each of several different textfields upon selection.

The data will be coming from a table in a database. I'm working with PHP and know almost nothing about Javascript.
 
Hi

What have you tried so far and where in your code you have problem ?

In the future please use Tek-Tips' cross-referencing, so write [ignore]thread216-1554251[/ignore] if you want a link to thread216-1554251.

Feherke.
 
Hi,

Thanks for replying. I've simplified the code just to include what I'm referring to. When I was doing it, I realised that I can't put the values through hidden fields as they would be inside the select tag so I need another way of doing it. You've done it by putting the value in the title tag, but I'd need 3 different values. Any idea what is the best way to do this?


<?php require_once('../../Connections/connCarat.php');

mysql_select_db($database_connCarat, $connCarat);
$query_rsClients = "SELECT * FROM Clients ORDER BY ClientID ASC";
$rsClients = mysql_query($query_rsClients, $connCarat) or die(mysql_error());
$row_rsClients = mysql_fetch_assoc($rsClients);
$totalRows_rsClients = mysql_num_rows($rsClients);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>
</head>
<body>
<form name="form1" action="">
<p>
<select name="select_client" id="select_client">
<option>Select an existing lead/client or create a new lead/client...</option>
<option value="1">New lead/client</option>
<?php
do {
$client_id = $row_rsClients['ClientID'];
$name = $row_rsClients['CompanyName'];
?>
<option value="<?php echo $client_id?>"><?php echo $name; ?></option>
<?php
} while ($row_rsClients = mysql_fetch_assoc($rsClients));
$rows = mysql_num_rows($rsClients);
if($rows > 0) {
mysql_data_seek($rsClients, 0);
$row_rsClients = mysql_fetch_assoc($rsClients);
}
?>
</select></p>
<p>Company Name: <input name="company_name" type="text" id="company_name" value="" size="37" /></p>
<p>Company Tel: <input name="tel" type="text" id="tel" value="" size="20" /></p>
<p>Company Email: <input name="email" type="text" id="email" value="" size="26" /></p>
<p><input name="submit" type="submit" value="Submit" /></p>
</form>
</body>
</html>
 
Hi

So there is only 1 [tt]select[/tt] and 3 [tt]hidden[/tt] [tt]input[/tt] fields. Then I would put the values in a JavaScript [tt]Array[/tt].

I do not understand your goal with those database-related operations. Could you show us a sample result set for that MySQL [tt]select[/tt] ? ( Including all needed fields, but only a couple of rows. )

In the future please post your code between [tt][ignore]
Code:
[/ignore][/tt] and [tt][ignore]
[/ignore][/tt] TGML tags.

Feherke.
 
There is 1 select and 3 text fields (not hidden). Once you select the client from the list, the company's details are put into the 3 fields. A sample result is:

ID - Name - Tel - Email
123 - CocaCola - 02081234567 - info@cocacola.com
124 - Surrey Council - 08456543456 - enquiries@surrey.co.uk
125 - Halifax - 01245678902 - info@halifax.co.uk

How do I put the values from the database table to a javascript array? I know very little about javascript so I'd need the exact code and as much explanation as possible please.

Many thanks for your help.
 
Hi

Something like this :
Code:
[teal]<?php[/teal]

[red]require_once[/red][teal]([/teal][green][i]'../../Connections/connCarat.php'[/i][/green][teal]);[/teal]

[COLOR=darkgoldenrod]mysql_select_db[/color][teal]([/teal][navy]$database_connCarat[/navy][teal],[/teal] [navy]$connCarat[/navy][teal]);[/teal]
[navy]$query_rsClients[/navy] [teal]=[/teal] [green][i]"SELECT * FROM Clients ORDER BY ClientID ASC"[/i][/green][teal];[/teal]
[navy]$rsClients[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_query[/color][teal]([/teal][navy]$query_rsClients[/navy][teal],[/teal] [navy]$connCarat[/navy][teal])[/teal] [b]or[/b] [b]die[/b][teal]([/teal][COLOR=darkgoldenrod]mysql_error[/color][teal]());[/teal]
[navy]$totalRows_rsClients[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_num_rows[/color][teal]([/teal][navy]$rsClients[/navy][teal]);[/teal]

[teal]?>[/teal]
[teal]<![/teal]DOCTYPE html PUBLIC [green][i]"-//W3C//DTD XHTML 1.0 Transitional//EN"[/i][/green] [green][i]"[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"[/URL][/i][/green][teal]>[/teal]
[teal]<[/teal]html xmlns[teal]=[/teal][green][i]"[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL][/i][/green][teal]>[/teal]
[teal]<[/teal]head[teal]>[/teal]
[teal]<[/teal]meta http[teal]-[/teal]equiv[teal]=[/teal][green][i]"Content-Type"[/i][/green] content[teal]=[/teal][green][i]"text/html; charset=utf-8"[/i][/green] [teal]/>[/teal]
[teal]<[/teal]title[teal]>[/teal]Form[teal]</[/teal]title[teal]>[/teal]
[teal]<[/teal]script type[teal]=[/teal][green][i]"text/javascript"[/i][/green][teal]>[/teal]
[teal]<![[/teal]CDATA[teal][[/teal]

[teal]<?php[/teal]

[navy]$data[/navy][teal]=[/teal][b]array[/b][teal]();[/teal]
[b]while[/b] [teal]([/teal][navy]$row_rsClients[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_fetch_assoc[/color][teal]([/teal][navy]$rsClients[/navy][teal]))[/teal]
  [navy]$data[/navy][teal][[/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'ClientID'[/i][/green][teal]]]=[/teal][b]array[/b][teal]([/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'CompanyName'[/i][/green][teal]],[/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'tel'[/i][/green][teal]],[/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'email'[/i][/green][teal]]);[/teal]

[b]echo[/b] [green][i]'var data='[/i][/green][teal],[/teal][COLOR=darkgoldenrod]json_encode[/color][teal]([/teal][navy]$data[/navy][teal]),[/teal][green][i]"\n"[/i][/green][teal];[/teal]

[b]if[/b] [teal]([/teal][navy]$totalRows_rsClients[/navy][teal])[/teal] [COLOR=darkgoldenrod]mysql_data_seek[/color][teal]([/teal][navy]$rsClients[/navy][teal],[/teal] [purple]0[/purple][teal]);[/teal]

[teal]?>[/teal]

[b]function[/b] [COLOR=darkgoldenrod]populate[/color][teal]([/teal]id[teal])[/teal]
[teal]{[/teal]
  [b]if[/b] [teal]([/teal]id in data[teal])[/teal] [teal]{[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'company_name'[/i][/green][teal]).[/teal]value[teal]=[/teal]data[teal][[/teal]id[teal]][[/teal][purple]0[/purple][teal]];[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'tel'[/i][/green][teal]).[/teal]value[teal]=[/teal]data[teal][[/teal]id[teal]][[/teal][purple]1[/purple][teal]];[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'email'[/i][/green][teal]).[/teal]value[teal]=[/teal]data[teal][[/teal]id[teal]][[/teal][purple]2[/purple][teal]];[/teal]
  [teal]}[/teal] [b]else[/b] [teal]{[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'company_name'[/i][/green][teal]).[/teal]value[teal]=[/teal][green][i]''[/i][/green][teal];[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'tel'[/i][/green][teal]).[/teal]value[teal]=[/teal][green][i]''[/i][/green][teal];[/teal]
    document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'email'[/i][/green][teal]).[/teal]value[teal]=[/teal][green][i]''[/i][/green][teal];[/teal]
  [teal]}[/teal]
[teal]}[/teal]

[teal]]]>[/teal]
[teal]</[/teal]script[teal]>[/teal]
[teal]</[/teal]head[teal]>[/teal]
[teal]<[/teal]body[teal]>[/teal]
[teal]<[/teal]form name[teal]=[/teal][green][i]"form1"[/i][/green] action[teal]=[/teal][green][i]""[/i][/green][teal]>[/teal]
[teal]<[/teal]p[teal]>[/teal]
[teal]<[/teal]select name[teal]=[/teal][green][i]"select_client"[/i][/green] id[teal]=[/teal][green][i]"select_client"[/i][/green] onchange[teal]=[/teal][green][i]"populate(this.options[this.selectedIndex].value)"[/i][/green][teal]>[/teal]
[teal]<[/teal]option[teal]>[/teal]Select an existing lead[teal]/[/teal]client [b]or[/b] create a [b]new[/b] lead[teal]/[/teal]client[teal]...</[/teal]option[teal]>[/teal]
[teal]<[/teal]option value[teal]=[/teal][green][i]""[/i][/green][teal]>[/teal]New lead[teal]/[/teal]client[teal]</[/teal]option[teal]>[/teal]
[teal]<?php[/teal]

[b]while[/b] [teal]([/teal][navy]$row_rsClients[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_fetch_assoc[/color][teal]([/teal][navy]$rsClients[/navy][teal]))[/teal]
  [b]echo[/b] [green][i]'<option value="'[/i][/green][teal],[/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'ClientID'[/i][/green][teal]],[/teal][green][i]'">'[/i][/green][teal],[/teal][navy]$row_rsClients[/navy][teal][[/teal][green][i]'CompanyName'[/i][/green][teal]],[/teal][green][i]"</option>\n"[/i][/green][teal];[/teal]

[teal]?>[/teal]
[teal]</[/teal]select[teal]></[/teal]p[teal]>[/teal]
[teal]<[/teal]p[teal]>[/teal]Company Name[teal]:[/teal] [teal]<[/teal]input name[teal]=[/teal][green][i]"company_name"[/i][/green] type[teal]=[/teal][green][i]"text"[/i][/green] id[teal]=[/teal][green][i]"company_name"[/i][/green] value[teal]=[/teal][green][i]""[/i][/green] size[teal]=[/teal][green][i]"37"[/i][/green] [teal]/></[/teal]p[teal]>[/teal]
[teal]<[/teal]p[teal]>[/teal]Company Tel[teal]:[/teal] [teal]<[/teal]input name[teal]=[/teal][green][i]"tel"[/i][/green] type[teal]=[/teal][green][i]"text"[/i][/green] id[teal]=[/teal][green][i]"tel"[/i][/green] value[teal]=[/teal][green][i]""[/i][/green] size[teal]=[/teal][green][i]"20"[/i][/green] [teal]/></[/teal]p[teal]>[/teal]
[teal]<[/teal]p[teal]>[/teal]Company Email[teal]:[/teal] [teal]<[/teal]input name[teal]=[/teal][green][i]"email"[/i][/green] type[teal]=[/teal][green][i]"text"[/i][/green] id[teal]=[/teal][green][i]"email"[/i][/green] value[teal]=[/teal][green][i]""[/i][/green] size[teal]=[/teal][green][i]"26"[/i][/green] [teal]/></[/teal]p[teal]>[/teal]
[teal]<[/teal]p[teal]><[/teal]input name[teal]=[/teal][green][i]"submit"[/i][/green] type[teal]=[/teal][green][i]"submit"[/i][/green] value[teal]=[/teal][green][i]"Submit"[/i][/green] [teal]/></[/teal]p[teal]>[/teal]
[teal]</[/teal]form[teal]>[/teal]
[teal]</[/teal]body[teal]>[/teal]
[teal]</[/teal]html[teal]>[/teal]
[small][maroon]Warning[/maroon] The above code was not tested[/small]

In the future please post tabular text aligned with spaces between [tt][ignore][tt][/ignore][/tt] and [tt][ignore][/tt][/ignore][/tt] TGML tags.

Feherke.
 
I've put this code into the browser but it doesn't seem to work. This is the source code I've copied from the browser. I'm using Opera and I need the code to work in opera only.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Form</title>

<script type="text/javascript">
<![CDATA[

var data={"NEW001":["Newton City Police Department","6016832041","smmcgee85@yahoo.com"],"TES001":["Test","0123456789","katie0129@hotmail.co.uk"]}

function populate(id)
{
  if (id in data) {
    document.getElementById('company_name').value=data[id][0];
    document.getElementById('tel').value=data[id][1];
    document.getElementById('email').value=data[id][2];
  } else {
    document.getElementById('company_name').value='';
    document.getElementById('tel').value='';
    document.getElementById('email').value='';
  }
}

]]>
</script>
</head>
<body>
<form name="form1" action="">
<p>
<select name="select_client" id="select_client" onchange="populate(this.options[this.selectedIndex].value)">
<option>Select an existing lead/client or create a new lead/client...</option>
<option value="1">New lead/client</option>
<option value="IMA001">Image</option>
<option value="NEW001">Newton City Police Department</option>
<option value="TES001">Test</option>
</select></p>
<p>Company Name: <input name="company_name" type="text" id="company_name" value="" size="37" /></p>
<p>Company Tel: <input name="tel" type="text" id="tel" value="" size="20" /></p>
<p>Company Email: <input name="email" type="text" id="email" value="" size="26" /></p>
<p><input name="submit" type="submit" value="Submit" /></p>
</form>
</body>
</html>
 
Hi

Oops. Sorry, I am not used with XHTML. Put line comments in front of the CDATA marks :
Code:
<script type="text/javascript">
[highlight]//[/highlight]<![CDATA[

// the code remains the same

[highlight]//[/highlight]]]>
</script>

Feherke.
 
Thank you so much! It works brilliantly! You've helped me a lot.
 
First post here. (I don't yet really consider myself a programmer. Graphics has been most of my experience but that was the closest fit I could find during registration).

I found this thread after many hours of search and study. The method outlined by "feherke" is just what I was needing.
I have this working on a test page, but was having trouble adding a second drop down list.

I will need two lists from the same table. But I am filtering each list to include only rows that match a certain criteria.

List 1 will have all IDs, Names, Images who are "male".
List 2 will have all IDs, Names, Images who are "female".

I have this working great accept the mysql_data_seek ignores the first row of each array. I studied the use of mysql_data_seek and from what I understand it starts the pointer over at 0 as it loops. So my guess is that I need to some how combine the two arrays and yet filter them at the select option. Is that correct?

Thanks,
TroyD
 
Here you go. It's not pretty, I'm sure, but I am still learning this stuff.
I use Dreamweaver and sometimes the Server Behavior panel will create code for me that causes problems do to my lack of experience. In this case, I think that the additional mysql_fetch_assoc is some how messing up the mysql_data_seek.
If I comment out those two lines added (one in each sql query), then the pointer works and I get the first line from each array. But it removes my reference for the record set in the DW Server Behavior panel. That wouldn't be a problem for most, I'm sure. But I use it to reference some other behaviors in that panel. So I don't know where I am going wrong here.

My guess is that I need to have one sql query and then create my two arrays with conditions that filter them by gender. But I can't figure out how to do that. I've been reading and studying for days. Thanks for your help.

TroyD

Code:
<?php require_once("../../Connections/dbCMS.php"); ?>
<?php
/*My sql is from one table where males and females are grouped. For my dropdowns, I need to break them apart
by gender. So I created two record sets.*/

mysql_select_db($database_dbCMS, $dbCMS);
$query_rsMales = "SELECT * FROM tblBreedersp WHERE sex = 'Male'";
$rsMales = mysql_query($query_rsMales, $dbCMS) or die(mysql_error());
$row_rsMales = mysql_fetch_assoc($rsMales);/*I did notice that DW inserts this line and might be causing the problem.*/
$totalRows_rsMales = mysql_num_rows($rsMales);

mysql_select_db($database_dbCMS, $dbCMS);
$query_rsFemales = "SELECT * FROM tblBreedersp WHERE sex = 'Female'";
$rsFemales = mysql_query($query_rsFemales, $dbCMS) or die(mysql_error());
$row_rsFemales = mysql_fetch_assoc($rsFemales);/*I did notice that DW inserts this line and might be causing the problem.*/
$totalRows_rsFemales = mysql_num_rows($rsFemales);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Admin: Insert Schedule Record
</title>

<script type="text/javascript">
//<![CDATA[
/*As you can see I don't totally understand the proper way to join two arrays and have them
filtered, each according to their gender listed in the table column.*/
<?php

$data=array();

while ($row_rsMales = mysql_fetch_assoc($rsMales))
  $data[$row_rsMales['id']]=array($row_rsMales['name'],$row_rsMales['number'],$row_rsMales['imagethumb1']);

echo 'var data=',json_encode($data),"\n";

if ($totalRows_rsMales) mysql_data_seek($rsMales, 0);

$data2=array();

while ($row_rsFemales = mysql_fetch_assoc($rsFemales))
  $data2[$row_rsFemales['id']]=array($row_rsFemales['name'],$row_rsFemales['number'],$row_rsFemales['imagethumb1']);

echo 'var data2=',json_encode($data2),"\n";

if ($totalRows_rsFemales) mysql_data_seek($rsFemales, 0);

?>

function populate(id)
{
  if (id in data) {
    document.getElementById('bname').value=data[id][0];
    document.getElementById('bnumber').value=data[id][1];
    document.getElementById('bimagethumb1').value=data[id][2];
  } else {
    document.getElementById('bname').value='';
    document.getElementById('bnumber').value='';
    document.getElementById('bimagethumb1').value='';
}
}
function populate2(id)
{
  if (id in data2) {
    document.getElementById('sname').value=data2[id][0];
    document.getElementById('snumber').value=data2[id][1];
    document.getElementById('simagethumb1').value=data2[id][2];
  } else {
    document.getElementById('sname').value='';
    document.getElementById('snumber').value='';
    document.getElementById('simagethumb1').value='';
  }
}

//]]>
</script>

</head>
<body id="adminschedulespbody">
<div class="InsertContainer">
  
  <form action="tblschedulesp_Insert.php" method="post" enctype="multipart/form-data" name="InsertForm" id="InsertForm">
    <div class="Header">Insert Breeding Schedule Record</div>
    <div class="HorizLine"><img src="../../WA_DataAssist/images/_tx_.gif" alt="" height="1" width="1" border="0" /></div>
    <table width="600" border="0" cellpadding="0" cellspacing="0" class="DataTable" id="inserttable">
      <tr>
        <th class="DataTableHeader">Pair Number:</th>
        <td class="DataTableCell"><input type="text" name="pair_id" id="pair_id" value="" size="5" tabindex="1" /></td>
        <th class="DataTableHeader">&nbsp;</th>
        <td class="DataTableCell"><input type="hidden" name="id" id="id" value="" size="" />        </td>
      </tr>
      <tr>
        <th class="DataTableHeader">Male:</th>
        <td class="DataTableCell">
        <select name="maleid" id="maleid"  onchange="populate(this.options[this.selectedIndex].value)" tabindex="2">
            <option>Select Name</option>
            <?php

while ($row_rsMales = mysql_fetch_assoc($rsMales))
  echo '<option value="',$row_rsMales['id'],'">',$row_rsMales['name'],"</option>\n";

?>
            </select>
          <input type="text" name="bname" id="bname" />
          <input type="text" name="bnumber" id="bnumber" />
          <input type="text" name="bimagethumb1" id="bimagethumb1" /></td>
        <th class="DataTableHeader">Female:</th>
        <td class="DataTableCell">
        <select name="femaleid" id="femaleid"  onchange="populate2(this.options[this.selectedIndex].value)" tabindex="2">
            <option>Select Name</option>
            <?php

while ($row_rsFemales = mysql_fetch_assoc($rsFemales))
  echo '<option value="',$row_rsFemales['id'],'">',$row_rsFemales['name'],"</option>\n";

?>
            </select>
          <input type="text" name="sname" id="sname" />
          <input type="text" name="snumber" id="snumber" />
          <input type="text" name="simagethumb1" id="simagethumb1" /></td>
      </tr>
      <tr>
        <th colspan="4" class="DataTableHeader"><input type="button" name="Insert" id="Insert" value="Insert" alt="Insert"/></th>
      </tr>
    </table>
  </form>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($rsMales);
mysql_free_result($rsFemales);
?>
 
Hi

TroyD said:
I did notice that DW inserts this line and might be causing the problem.
Well, that is one reason for me to hate Dreamweaver and other similar things.

The normal way would be to just remove those two lines. Or maybe just commenting them out could help :
Code:
[COLOR=darkgoldenrod]mysql_select_db[/color][teal]([/teal][navy]$database_dbCMS[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal]);[/teal]
[navy]$query_rsMales[/navy] [teal]=[/teal] [green][i]"SELECT * FROM tblBreedersp WHERE sex = 'Male'"[/i][/green][teal];[/teal]
[navy]$rsMales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_query[/color][teal]([/teal][navy]$query_rsMales[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal])[/teal] [b]or[/b] [b]die[/b][teal]([/teal][COLOR=darkgoldenrod]mysql_error[/color][teal]());[/teal]
[gray][highlight]//[/highlight]$row_rsMales = mysql_fetch_assoc($rsMales);[/gray]
[navy]$totalRows_rsMales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_num_rows[/color][teal]([/teal][navy]$rsMales[/navy][teal]);[/teal]

[COLOR=darkgoldenrod]mysql_select_db[/color][teal]([/teal][navy]$database_dbCMS[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal]);[/teal]
[navy]$query_rsFemales[/navy] [teal]=[/teal] [green][i]"SELECT * FROM tblBreedersp WHERE sex = 'Female'"[/i][/green][teal];[/teal]
[navy]$rsFemales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_query[/color][teal]([/teal][navy]$query_rsFemales[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal])[/teal] [b]or[/b] [b]die[/b][teal]([/teal][COLOR=darkgoldenrod]mysql_error[/color][teal]());[/teal]
[gray][highlight]//[/highlight]$row_rsFemales = mysql_fetch_assoc($rsFemales);[/gray]
[navy]$totalRows_rsFemales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_num_rows[/color][teal]([/teal][navy]$rsFemales[/navy][teal]);[/teal]
Or rewind the resultsets after those lines to undo their unwanted effect :
Code:
[COLOR=darkgoldenrod]mysql_select_db[/color][teal]([/teal][navy]$database_dbCMS[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal]);[/teal]
[navy]$query_rsMales[/navy] [teal]=[/teal] [green][i]"SELECT * FROM tblBreedersp WHERE sex = 'Male'"[/i][/green][teal];[/teal]
[navy]$rsMales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_query[/color][teal]([/teal][navy]$query_rsMales[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal])[/teal] [b]or[/b] [b]die[/b][teal]([/teal][COLOR=darkgoldenrod]mysql_error[/color][teal]());[/teal]
[navy]$row_rsMales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_fetch_assoc[/color][teal]([/teal][navy]$rsMales[/navy][teal]);[/teal]
[navy]$totalRows_rsMales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_num_rows[/color][teal]([/teal][navy]$rsMales[/navy][teal]);[/teal]
[highlight][b]if[/b] [teal]([/teal][navy]$totalRows_rsMales[/navy][teal])[/teal] [COLOR=darkgoldenrod]mysql_data_seek[/color][teal]([/teal][navy]$rsMales[/navy][teal],[/teal] [purple]0[/purple][teal]);[/teal][/highlight]

[COLOR=darkgoldenrod]mysql_select_db[/color][teal]([/teal][navy]$database_dbCMS[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal]);[/teal]
[navy]$query_rsFemales[/navy] [teal]=[/teal] [green][i]"SELECT * FROM tblBreedersp WHERE sex = 'Female'"[/i][/green][teal];[/teal]
[navy]$rsFemales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_query[/color][teal]([/teal][navy]$query_rsFemales[/navy][teal],[/teal] [navy]$dbCMS[/navy][teal])[/teal] [b]or[/b] [b]die[/b][teal]([/teal][COLOR=darkgoldenrod]mysql_error[/color][teal]());[/teal]
[navy]$row_rsFemales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_fetch_assoc[/color][teal]([/teal][navy]$rsFemales[/navy][teal]);[/teal]
[navy]$totalRows_rsFemales[/navy] [teal]=[/teal] [COLOR=darkgoldenrod]mysql_num_rows[/color][teal]([/teal][navy]$rsFemales[/navy][teal]);[/teal]
[highlight][b]if[/b] [teal]([/teal][navy]$totalRows_rsFemales[/navy][teal])[/teal] [COLOR=darkgoldenrod]mysql_data_seek[/color][teal]([/teal][navy]$rsFemales[/navy][teal],[/teal] [purple]0[/purple][teal]);[/teal][/highlight]

Feherke.
 
Feherke said:
Or rewind the resultsets after those lines to undo their unwanted effect :

That did it! Thanks so much. Now I have a working script and my server behaviors still show up in the DW panel.

I really appreciate it. I have lots of stuff to learn, I know but it's taking time.

Was my additional drop down menu in the js done correctly? Even though it works, I know that doesn't mean I did it with proper code. Just wanted to make sure.

Thanks,TroyD
 
Hi

Nothing wrong there, but I would probably do it differently.

I would choose the [tt]id[/tt]s so the [tt]input[/tt]'s [tt]id[/tt]s can be easily deduced from the [tt]select[/tt]'s [tt]id[/tt]s, then would be easier to change the populate() function to handle both genders' data.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top