PHP Help.... Again
Author
Discussion

BliarOut

Original Poster:

72,863 posts

263 months

Sunday 19th September 2004
quotequote all
I use the following query in a PHP form/script.

SELECT DISTINCT CONCAT( surname, ', ', givenname ) AS full_name, Y.adocid as DOCID
FROM trusr as X
LEFT OUTER JOIN proc as Y ON Y.ADOCID = X.uid
WHERE givenname IS NOT NULL AND surname IS NOT NULL
ORDER BY full_name

This query returns a concatenation of given and surname to populate a dropdown list to select individuals (full_name) and it works just fine. I can pass the variable via a POST to my php action.

(The query is good if I run it natively in MySQl and returns the data I expect. two columns, full_name and DOCID)


I want to also pass the variable DOCID from above to the php action. I added # in the the PHP script, because it creates a dropdown in the post otherwise!!!!

<?#php #_POST[fullname] and #_POST[DOCID]; ?#>
<#select name="DocName" id="DocName">
<?#php
do {
#?>
<option value="<?#php echo $row_Recordset1['full_name']?>"><?#php echo $row_Recordset1['full_name']?></option>
<?#php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
$rows = mysql_num_rows($Recordset1);
if($rows > 0) {
mysql_data_seek($Recordset1, 0);
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
}
#?>


Any ideas how I can proceed? All I want to do is reference DOCID as $DOCID to pass into a SQL query on the PHP script which forms the action of the form... Err, if you see what I mean!

I can post the full PHP scripts if anyone is willing to help... It's all in a good cause again
Thanks

EDIT:

It was very late and I was tired when I first posted this!

>>> Edited by BliarOut on Sunday 19th September 11:08

john_p

7,073 posts

274 months

Sunday 19th September 2004
quotequote all
Not too sure on your script but what I'd normally do is

echo "<select name="chosenID">";
$result=mysql_query("select ID,Name from xxxxx");
while ($row=mysql_fetch_array($result)) {
echo "<option value="".$row["ID"]."">".$row["Name"];
}

you can then refer to the field in the relevant script as $chosenID or perhaps $HTTP_POST_VARS["chosenID"] if you haven't got register_globals on

size13

2,033 posts

281 months

Monday 20th September 2004
quotequote all
Send the code over to me if you havn't already fixed it.

Am I right in understanding that you want to pass two different values through #_POST with one option?

BTW instead of using
<?#php echo $row_Recordset1['full_name']?>
you can just use
<?=$row_Recordset1['full_name']?>

BliarOut

Original Poster:

72,863 posts

263 months

Monday 20th September 2004
quotequote all
Thanks very much for the offer, I have just sussed it!

What worked was something like.

$row_Recordset1'[DOCID]$row_Recordset1['full_name'] (Lots of bits stripped out to display it here)

I was trying to do something similar to an Access "bound column" but hadn't got my head round a select option.

ie. store this value, but display the other value.

I'll tidy up the code like you suggested though!

Thanks for offering!

size13

2,033 posts

281 months

Monday 20th September 2004
quotequote all
<?=$row_Recordset1['full_name']?> is really only useful for displaying variable values within html code. So remember to still use echo if it's which a block of php code