Page 1 of 1
dynamic list
Posted: Mon Oct 04, 2004 10:51 am
by devilgrendall
hi,
i was wondering if anyone could help me???
Ive made a page to enter a news article in to a database. I also need to pull out building names from the second database into a select box so the articles and the buildings are linked. Ive tried using the below but it just comes up blank.
Code: Select all
<select name="Buildinglink">
<? echo "<option value='$buildingname' selected='selected'>$buildingname</option>" ?>
</select>
any suggestions??
thanks
Jay

Posted: Mon Oct 04, 2004 10:58 am
by feyd
your install may not support short_tags, try using <?php
Posted: Mon Oct 04, 2004 11:04 am
by devilgrendall
hi,
no it does support short tags
<banging head against the wall></>
jay
Posted: Mon Oct 04, 2004 11:06 am
by feyd
where/how is $buildingname created then?
Posted: Mon Oct 04, 2004 11:17 am
by devilgrendall
Hi feyd,
the building names are already added to the database through a different edit page.
Code: Select all
<?php
error_reporting(0);
$host = "localhost";
$user = "***";
$password = "****";
$dbname = "****";
$tablename = "*****";
$link = mysql_connect ($host, $user, $password);
$sql = "SELECT * FROM " . $tablename . " ORDER BY buildingname Desc" ;
$result = mysql_db_query($dbname,$sql,$link);
?>
then in the html the select code is added.
i did print query to make sure it was pulling it out ok, it is connecting ok, i think i have just done the select code wrong, im still new to php and its more the trial and error way.
Posted: Mon Oct 04, 2004 11:25 am
by feyd
that doesn't set $buildingname. you need to fetch (hint) the records, then you'll have access to the name (depending on how you fetch and extract the row)
Posted: Mon Oct 04, 2004 11:48 am
by devilgrendall
hey
thanks for that
Code: Select all
<? $dbbuild = mysql_result ($result,$indexcount,buildingname); ?>
<select name="buildinglink">
<?php print mysql_result . "<option value='$dbbuild' selected='selected'>$dbbuild</option>" ?>
</select>
it does it now but only with the first name in the db, just doesnt loop to pull out all the others
grr
thanks for you help though
jay
Posted: Mon Oct 04, 2004 11:51 am
by feyd
you'll need a while/for/do loop, and I'd suggest using [php_man]mysql_fetch_assoc[/php_man] instead of result.. or at the least, make sure you quote your literal strings.