473,403 Members | 2,071 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

I am getting double of all my units in this code. any ideas?

I work in a hospital and I am using php, postgres and apache to replace
old paradox databases. I have made a form that contains a dropdown
menu of the hospital units so I can choose the group of patient based
on the unit they are on. For some reason my code has each unit
appearing 2 times in the drop down so the dropdown looks like this

unit1
unit1
unit2
unit2

and so on. I have tested the query in the pgadim query window and I
get only one occurance. then I wrote the simple script:

?php
pg_connect("host=localhost dbname=liberty user=postgres
password=password") or die;
$qunit = pg_query("SELECT unitid, unitname FROM li_unit ORDER BY
unitname");
while($myunits=pg_fetch_array($qunit)){
$eachid=$myunits["unitid"];
$eachunit=$myunits["unitname"];
echo "$eachid $eachunit<br>\n";
}
?>
and I get the simple out put of

1 unit1
2 unit2
3 unit3
4 unit4

Yet the below code gives me the double occurance of each unit. here is
the code.
<html>
<head>
<body>

<form name="unitchoice" method="post" action="<?php print
$_SERVER['PHP_SELF']?>">
<select name="homeunits">
<?php
pg_connect("host=localhost dbname=liberty user=postgres
password=password") or die;
$qunit = pg_query("SELECT unitid, unitname FROM li_unit ORDER BY
unitname");
while($myunits=pg_fetch_array($qunit)){
$eachid=$myunits["unitid"];
$eachunit=$myunits["unitname"]; ?>
<option value=<?php echo $eachunit;?>><?php echo
$eachunit;?></option>
<?php
}
?>
</select>
<input type="Submit" name="updateunit" value="Change Unit">
</form>

</body>
</head>
</html>

Any suggestions?

May 12 '06 #1
3 1137
Rik
rh****@gmail.com wrote:
$qunit = pg_query("SELECT unitid, unitname FROM li_unit ORDER BY
unitname");
while($myunits=pg_fetch_array($qunit)){
$eachid=$myunits["unitid"];
$eachunit=$myunits["unitname"];
}
Any suggestions?


What happens if you instead use pg_fetch_assoc($qunit)?

pg_fetch_array gives both a numerical and a associative array, maybe that's
the issue. It should not give the error in this code, but maybe you ommited
some seemingly insignificant code. I have no PostgreSQL-server, so I can't
test it.

Grtz,
--
Rik Wasmus
May 12 '06 #2
Still getting the same thing. There must be a bug. maybe it has
something to do with it being part of a table?

May 13 '06 #3
Rik
rich wrote:
Still getting the same thing. There must be a bug. maybe it has
something to do with it being part of a table?


hmmmz, atih with pf_fetch_assoc you're sure there is only the associative
array, so that would take care of doubles on that side (and uses less space,
is about the same speed, so always a good idea).

What is the exact reason you assign it to the variable $eachunit and
$eachid? The only thing I can think of is that somehow, there is a second
loop through the code.

PHP doesn't care you echo it in a select box...... What does yout HTML
output look like?

What about trying:
printf('option value="%s">%s</option>', $myunits['unitid'],
$myunits['unitname']);

Else, for debugging purposes:
$check = array();
while($myunits=pg_fetch_assoc($qunit)){
$check[] = $myunits;
}
print_r($check);

What does that tell you?

Grtz,
--
Rik Wasmus
May 13 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Adrian Gibbons | last post by:
Hello, I need to get the units of a number. i.e. if I had 12345 then I would want '5'. I was looking at dividing the number by ten and using the modulus operator repeatedly until I had only...
2
by: John M | last post by:
Hi, I have a continuous form which shows a record on each line. Further details are available by clicking on a box which runs code to open a further form to give more details of the record. It...
2
by: TheSeeker | last post by:
Hi, As part of a larger project, I am trying to use the GNU Units program to provide unit conversions between quantities. My first iteration, which worked OK, was to simply use units as a...
14
by: cj | last post by:
VB2003. I need a large positive integer. Which is larger int64 or double? I see int64 also apparently is known as long and will hold -9,223,372,036,854,775,808 through...
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
18
by: kwikius | last post by:
Well lads :-)... looking at your Boost Units library the impression I get is that you got your library into boost Before writing anything much apart from some documentation, which was AFAICS even...
2
by: pukhton | last post by:
I am getting this error each time I run my form in Access. I have a table calls "Medications" and it has three colums (Medication_Name, Concentration, Units) then I have another table name Main...
1
by: jonnyothan | last post by:
The following code isn't producing expected results: class Selectable { bool IsSelected() const; }; class Unit : public Selectable { };
2
by: andersond | last post by:
I have a webpage that allows insurance agents to enter a group of trucks for an insurance policy. I want to keep track of the number of power units (tractors or trucks), the number of trailers and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.