
palacios
New Members-
Posts
4 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
palacios's Achievements

Newbie (1/5)
0
Reputation
-
Dear Forum People, I have a question about PHP. I'm trying to use an array several times in combination with 'while' and 'mysql_fetch_assoc'. the reason i have this requirements is because i need to display some googlemap coordinates inside a javascript and later on the html page i want to display other data coming from the database. the code will explain the situation: this is the code that goes before the html <head> <?php //$where_query = "bedrooms_nbr = $form_bedrooms AND max_people > $form_adults AND available = '1'"; $sql_search = mysql_query("SELECT id, available, building_id, max_people, min_nights, bedrooms_nbr, bedrooms_interconn FROM property_flats WHERE $where_query GROUP BY building_id "); confirm_query($sql_search); //this is a function $num_rows = mysql_num_rows($sql_search); ?> <script type="text/javascript"> //<![CDATA[ // Sample hotel list - LAT/LNG/Name hotels = new Array( <?php while ($grow = mysql_fetch_assoc($sql_search)) { $gbuilding_id = ($grow['building_id']); //this goes on the next query --- $gsql_building = mysql_query("SELECT ordername, g1, g2 FROM property_buildings WHERE id = '$gbuilding_id'") ; confirm_query($gsql_building); //this is a function $grow_building = mysql_fetch_assoc ($gsql_building) ; $gordername = $grow_building['ordername']; $gg1 = $grow_building['g1']; $gg2 = $grow_building['g2']; echo "[". $gg1 . ", " . $gg2 . ", '". $gordername ."'], \n" ; } echo "[, , '']"; //reset($sql_search); then inside the page i repeat the same loop in a very similar way but with many more variables fetch from the db <?php // //mysql_query is in the <head> for gmap to work echo '<h3 class="">'. $num_rows .' Apartments found</h3>'; //print_r ($main_query_array) ; // $k=1; //this is for alternate colour row while ($row = mysql_fetch_assoc($sql_search)) { $id = $row['id'] ; $air_co = $row['air_co'] ; $bathrooms = $row['bathrooms'] ; $bedrooms = $row['bedrooms'] ; $ensuite = $row['ensuite'] ; $max_people = $row['max_people'] ; // etc etc .... $building_id = ($row['building_id']); //this goes on the next query --- and refers to next apartment page-- // this is to know the BUILDING NAME{{{ $sql_building = mysql_query("SELECT id, name, description, streetnum, street, areacode, picfolder, main_picture FROM property_buildings WHERE id = '$building_id'") ; confirm_query($sql_building); //this is a function $row_building = mysql_fetch_assoc ($sql_building) ; $name = $row_building['name']; $postcode = $row_building['areacode']; $description = $row_building['description']; // etc etc ..... $goto = 'apartment.php?id='.$building_id.''; // echo '<a class="previewimg fl" href="'.$goto.'" title="'.$name.'"><img src="'.$folder_main_picture.'" alt="'.$name.'" /></a> <small class="fr tr"><br /><b>Minimum Stay: '.$min_nights.' Night</b></small> <h3><a href="'.$goto.'">'.$name.'</a></h3> <div class="address">'. $streetnum .' '.$street. ' - ' . $postcode.' [ <a href="#">Show on map</a> ]</div> <p>'; $extract = substr ($description, 0, 250); // find position of last space in extract $lastSpace = strrpos($extract, ' '); // use $lastSpace to set length of new extract and add ... echo substr($extract, 0, $lastSpace).'... '; //echo '<a href="details.php?article_id='.$row['article_id'].'"> More</a>'; echo '<a href="'.$goto.'">more ยป</a></p> <table class="roomlist full"> <thead> <tr> <th class="tl w13">Available room types</th> <th class="tc w13">Maximum Persons</th> <th class="tr w13">Rate</th> </tr> </thead> <tbody>'; <!-- a table to show all information about an hotel ....-->' </tbody> </table> <div class="clear"> </div> </div> <hr class="thin"/> <!-- End of Search item }}}-->' ; $k++ ; } ?> please note: if i remove the loop for googlemap at the top of the page, the second loop for the hotel information dispalys correctly; and if i leave both loops working in the same page, only the google map comes up correctly. any suggestion? is it because i made a mistake in the php code? or the javascript for googlemaps messes up with the rest of the code? many thanks in advance. regards, giulio
-
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++ ; } ?>
-
Thank you all for your help. I think I have some errors in the code somewhere else, if I use your revised code I have on the db some other characters like 'm' or 'c', for example: linen_change: l maid_service: m cctv: c actually -now that i'm writing it - looks like the db is filling in the cells with the firs letter of the field name... strange... my questions now are: * is it really necessary to grasp the value of the database and link it to a variable (as shown in mjdamao post)? does it bring any advantage? * i understand the suggestion to use 1-0 instaed of Y-N in the database, but shall i change also the field type? at the moment is set up as 'char' with lenght '1', I dont see any boolean option for the field type or am I missing something? thanks a lot again giulio
-
Hi, I'm trying to use check-boxes in a webpage to update the information kept in a database. I managed to understand how it works with text but with checkbox i dont even know if it possible. <form id="form1" name="form1" method="post" action=""> <p> <label for="name">name:</label> <input name="name" type="text" class="widebox" id="name" value="<?php echo htmlentities($row['name']); ?>" /> <!-- so far so good --> </p> <p> <label for="air_conditioning">air-conditioning</label> <input name="air_conditioning" value="air_conditioning" type="checkbox" name="air_conditioning" id="air_conditioning" <?php // i came up with this code but it doenst work, the display from the db comes correct but if i want to update using the checkbox, nothing really happens. $yesorno = ($row['air_conditioning']); $option = $yesorno == 'Y' ? "checked" : "unchecked"; echo ($option); ?> /> </p> <p> <input type="submit" name="update" value="save changes!" /> <input name="id" type="hidden" value="<?php echo $row['id']; ?>" /> </p> </form> please advice and thank you in advance, giulio