Jump to content

while (something) {etc} *** am i using correctly?


palacios

Recommended Posts

hi phpfreaks,

 

i'm trying to display a list of available flats from a big database (at lease big for me).

 

i'm following a guide book, so far what i wrote works well but i'm sure there is a better way of doing this.

 

i'm fetching data from a database, in particular 2 tables, one with few rows (building_name) and another quite big (145rows, property_flats).

I'm using a WHILE loop to display the available flats, if i put all the variables inside the loop the result on the browser is fine, if i put the variables before the loop the list of all available flats is a repetition of just one flat for a number of times equals to the total flats available -1 (i.e. there are 9 flats available, i see the firs flat repeated 8 times).

 

please have a look at the code below and i'm open to suggestion.

 

thank you very much for your help

 

<?php
		$sql = "SELECT * FROM property_flats WHERE agent = '1' ORDER BY building_id, flat_number DESC";
		$result = mysql_query($sql) or die (mysql_error());

		$k=1;

		?>

		<?php while ($row = mysql_fetch_array($result)) { 
				  //{{{ all variables (building_flat TABLE)
		 	$id = $row['id'] ;
			$category = $row['category'] ; 
			$a_dish_w = $row['a_dish_w'] ; 
			$a_dryer = $row['a_dryer'] ;
			$a_washing_m = $row['a_washing_m'] ;
			$agent = $row['agent'] ;
			$air_co = $row['air_co'] ;
			$available = $row['available'] ;
			$balcony = $row['balcony'] ;
			$bathroom_prod = $row['bathroom_prod'] ;
			$bathrooms = $row['bathrooms'] ;
			$bedrooms = $row['bedrooms'] ;
			$bedrooms_interconn = $row['bedrooms_interconn'] ; 
			$beds_king_s = $row['beds_king_s'] ;
			$beds_queen_s = $row['beds_queen_s'] ;
			$beds_single = $row['beds_single'] ;
			$beds_sofa = $row['beds_sofa'] ;
			$beds_twins = $row['beds_twins'] ;
			$description = $row['description'] ;
			$dining_room = $row['dining_room'] ;
			$double_glaz = $row['double_glaz'] ;
			$e_dvd = $row['e_dvd'] ;
			$e_fans = $row['e_fans'] ;
			$e_hifi = $row['e_hifi'] ;
			$e_safe = $row['e_safe'] ;
			$e_satellite_tv = $row['e_satellite_tv'] ; 
			$e_alarmclock = $row['e_alarmclock'] ;
			$e_hairdryer = $row['e_hairdryer'] ;
			$ensuite = $row['ensuite'] ;
			$extra_bed = $row['extra_bed'] ;
			$flat_number = $row['flat_number'] ;
			$floor = $row['floor'] ;
			$floor_carpet = $row['floor_carpet'] ; 
			$floor_wood = $row['floor_wood'] ;
			$floor_marble = $row['floor_marble'] ;
			$floors_split = $row['floors_split'] ;
			$furnished = $row['furnished'] ;
			// }}}
		 	// {{{this is to know the building name
		 	$building_id = ($row['building_id']);
			$building_name = "SELECT building_id, building, areacode FROM buildings_name WHERE building_id = '$building_id'";
			$get_building_name = mysql_query($building_name) or die (mysql_error());
			$thename = mysql_fetch_assoc ($get_building_name) ;
			$name = $thename['building'];
			$postcode = $thename['areacode'];
			//}}}		 
		?>
		<dl><dt><span class='backlight'><?php echo $k; ?></span> areacode: <span class='bolder'><?php echo $postcode ; ?></span>
		<dd class='img'><a title='click for more info' href='/property-agent.php?id=<?php echo $id; ?>'><img src='property-pics/<?php echo $picfolder ; ?>/thumb.jpg' alt='available property'  /></a></dd>
		<dd class='desc'><a name='<?php echo $picfolder ;?>' id='<?php echo $id; ?>'></a>
		<b><?php echo $typeflat . " " . $flat_number . ", " . $name . "</b><br />" . $description ;?>
		<br /><br />
		</dl>
		<!-- more code to add...... -->
		<?php $k++ ;  
		}			
		?>



Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.