dynamic list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
devilgrendall
Forum Newbie
Posts: 17
Joined: Fri Sep 10, 2004 10:29 am
Location: Warwickshire
Contact:

dynamic list

Post 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
:?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

your install may not support short_tags, try using <?php
devilgrendall
Forum Newbie
Posts: 17
Joined: Fri Sep 10, 2004 10:29 am
Location: Warwickshire
Contact:

Post by devilgrendall »

hi,

no it does support short tags

<banging head against the wall></>

jay
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

where/how is $buildingname created then?
devilgrendall
Forum Newbie
Posts: 17
Joined: Fri Sep 10, 2004 10:29 am
Location: Warwickshire
Contact:

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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)
devilgrendall
Forum Newbie
Posts: 17
Joined: Fri Sep 10, 2004 10:29 am
Location: Warwickshire
Contact:

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply