Home > Archive > PHP SQL > March 2008 > function problem involving query
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
function problem involving query
|
|
| Henny Boxa 2008-03-25, 4:20 am |
| I'm trying to construct a database of old houses including the parts
they are made of as roof construction, floor construction, types of
windows, vaults, etc. To do that I set up several tables. One
containing the house id, address, last visit, etc. For each of the
construction items there is a tabel containing the construction id and
the short description. Both tables should be linked by a table
containg the house id numbers and the fitting construction id numbers.
As there is much similarity in getting the right descriptions and
inserting the right values into the right tables I tried to make
functions to do that. Somehow this does't work.
An example for doing this for vaults is here:
(It is not in English, here follows a kind of translation)
.......
Vault:
<select name = "vaulttype">
<?php
$sqlvlt = 'SELECT vaultnr, description FROM vaulttype ORDER BY
`vaultr` ASC';
$resultvlt =mysql_query($sqlvlt,$conn)or die("No vault type today");
while($row = mysql_fetch_row($resultvlt))
{
echo "<option value=\"";
echo $row[0]."\">";
echo $row[1]."</option>\n";
}
?>
</select>
<input type="submit" name="vault" value="Submit">
</FORM>
<?php
$thisisit = $_POST['vaulttype'];
//hereafter testing for double values and actually inserting
?>
........
This works fine.
The function so far goes:
<?php
function getconstruction($construction){
global $houseid;
global $conn;
$a = $construction;
$b = $construction."type";
$c = $construction."nr";
echo $a.": ";
echo "<SELECT NAME = \"$b\">";
$sql = "SELECT $c, description FROM $b ORDER BY '$c' ASC";
$result = mysql_query($sql,$conn)or die(mysql_error());
while($row = mysql_fetch_row($result))
{
echo "<option value=\"";
echo $rij[0]."\">";
echo $rij[1]."</option>\n";
}
echo "</select>";
echo "<input type=\"submit\" name=\"$a\" value=\"Submit\">";
$gotconstruction = $_POST['vaulttype'];
return $gotconstruction;
}
getconstruction(vault);
?>
Now I get the list I ask for but further nothing whatsoever.
When I ask for the value of $gotconstruction the answer is vaulttype,
while when asking for $thisisit the answer is the number I want.
There are no error messages.
What is it I'm overlooking?
What is it I'm doing wrong?
How should I tackle this?
Thanks in advance,
Henny Boxa
| |
| Henny Boxa 2008-03-28, 7:12 pm |
| On Wed, 26 Mar 2008 08:06:45 +0000 wrote David Quinton
<usenet_2005D_email@REMOVETHISBITbizorg.co.uk>:
>On Tue, 25 Mar 2008 09:21:58 +0100, Henny Boxa <tirelibom@hotnet.com>
>wrote:
>
>
>I'm not totally sure I understand fully but AFAICT you're assuming
>that you are POSTING from within the Function.
>
>But the POST will be to the whole script - not just to that Function?
I'm afraid I was overlooking that.
Thank you,
Henny
|
|
|
|
|