Jump to content

ramone_johnny

Members
  • Posts

    50
  • Joined

  • Last visited

Everything posted by ramone_johnny

  1. Hey guys, I have a basic form that contains a number of checkboxes, all with the same name. See below... <input type='checkbox' name='share_category[]' value='Car Accommodation'>Car Accommodation <input type='checkbox' name='share_category[]' value='Employed only'>Employed only <input type='checkbox' name='share_category[]' value='Prefer someone quiet'>Prefer someone quiet These checkbox values are being pulled from the database. There's roughly 25 checkboxes. That's all good. On the following page, I'm using this piece of code to split up the array and write it to screen (to debug and make sure the correct values are being passed) $checked = $_POST['share_category']; for($i=0; $i < count($checked); $i++){ echo $checked[$i] . "<br/>"; } Which gives me ..... Car Accommodation Employed only Prefer someone quiet ...on the confirmation page. I should note that this form is posting data to a confirmation page, so users can take a look at what they've entered, and "go back" if they need to an ammend their entry before publishing it to the database. This is where my question comes in. How can I show the correct checkboxes ticked when they go back? Here's a single checkbox option that I have working using session variables. I'm ok with this. I understand how it works. <input type="checkbox" name="share_hide" value="1" <? if(isset($_SESSION['share_hide'])) if($_SESSION['share_hide'] == 1 ) echo "checked"?>> I just don't know how to "pull apart" the array to see which boxes they've checked. I would assume it's an "instring" type function? Oh, and lastly (my apologies) ...here is the code that creates the checkboxes. <? echo "<table width='100%' border='0' cellpadding='0' cellspacing='0' class='body_text' style='padding-left:20px; padding-right:15px;'>"; $strSQL = mysql_query("SELECT * FROM tblcategories ORDER BY cat_ID ASC"); $boxes_per_row = 4; for($x = 0; $r = mysql_fetch_array($strSQL); $x++){ if($x % $boxes_per_row == 0){ echo "<tr>"; } $cat_category = $r["cat_category"]; echo "<td><input type='checkbox' name='share_category[]' value='$cat_category'>$cat_category<td>"; if ($x % $boxes_per_row == ($boxes_per_row)-1) { echo "</tr>"; } } if($x != mysql_num_rows($strSQL)){ echo "</tr>"; } echo "</table>"; ?>
  2. Thanks Zane. There are, unfortunately quite a few variables being passed that I don't need. I think I might have to stick to the way I'm doing it. Looks a bit clunky, but works. Cheers mate.
  3. Yes, I have a selection of checkboxes that contain an array. The rest are just regular entries (text areas, drop downs etc) It just felt "clunky" writing all of the session variables out like that.
  4. Im passing form values over to a confirmation page where Im setting session variables in order to allow the user to "go back" if they wish, to ammend their previous entries. I just wanted to ask....this seems very cumbersome. Is there a smarter way to do this? Because I have about 50 values from the form. $_SESSION['share_header'] = isset($_REQUEST["share_header"]) ? $_REQUEST["share_header"] : ""; $_SESSION['share_rent'] = isset($_REQUEST["share_rent"]) ? $_REQUEST["share_rent"] : ""; $_SESSION['share_bond'] = isset($_REQUEST["share_bond"]) ? $_REQUEST["share_bond"] : ""; $_SESSION['share_proptype'] = isset($_REQUEST["share_proptype"]) ? $_REQUEST["share_proptype"] : ""; $_SESSION['theDate'] = isset($_REQUEST["date1"]) ? $_REQUEST["date1"] : ""; $_SESSION['share_num'] = isset($_REQUEST["share_num"]) ? $_REQUEST["share_num"] : ""; $_SESSION['share_street'] = isset($_REQUEST["share_street"]) ? $_REQUEST["share_street"] : ""; $_SESSION['share_location'] = isset($_REQUEST["search"]) ? $_REQUEST["search"] : ""; $_SESSION['share_description'] = isset($_REQUEST["share_description"]) ? $_REQUEST["share_description"] : "";
  5. Hey guys, I have code here written in XML/ASP that I need some help with. Its a pop window that launches a Google map, that allows users to "verify" the entered address. I have the values passing okay to the popup window, I'm just lost as to how I can convert this page to PHP. Is there anyone here that is knowledgeable with Google maps? I should probably mention that this script shows numerous markers when an exact match isn't found, allowing the user to "click" on the right marker, which repopulates the parent form (with the correct address) <!-- #INCLUDE VIRTUAL="/includes/adovbs.inc" --> <!-- #INCLUDE VIRTUAL="/includes/declarations.asp" --> <!-- #INCLUDE VIRTUAL="/includes/functions.asp" --> <html> <head> <meta name="robots" content="noindex,nofollow"> <link rel="SHORTCUT ICON" href="http://www.bleh.com/web.ico"/> <title>Website | Verify Address</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="/includes/white.css"> <br> <? $num = $_REQUEST["num"] ; $street = $_REQUEST["street"] ; $suburb = $_REQUEST["suburb"] ; $state = $_REQUEST["state"] ; $pcode = $_REQUEST["pcode"] ; $pcode_asis = $pcode ; echo "the number is : " . $num . " : " . "<br>" ; echo "the street is : " . $street . " : " . "<br>" ; echo "the suburb is : " . $suburb . " : " . "<br>" ; echo "the state is : " . $state . " : " . "<br>" ; echo "the pcode is : " . $pcode . " : " . "<br><hr>" ; exit() ; ?> <% CONST_ZOOM = 15 ; //' higher number means closer in zoom // This is the magic url with magic google key: baseURL = "http://maps.google.com/maps/geo?output=xml&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" ; // so do we have any addresses to display? // let's find out... //' Master array to hold the info returned from the geocode query addresses( ; foundAddrMax = -1 ; matchPost = 0 ; //' will match on first found location unless overridden //Dim num, street, suburb, city, state, pcode //' First, define the function to be called by the mainline code to test addresses: Function TryAddress( addr ) //' try to geocode this address URL = baseURL & Escape(addr) //' DEBUG: Response.Write "trying [" & URL & "]<br>" & vbNewLine Set http = Server.CreateObject("MSXML2.ServerXMLHTTP") http.open "GET", URL http.send Set xml = Server.CreateObject("Microsoft.XMLDom") xml.LoadXML http.ResponseText Set places = xml.getElementsByTagName("Placemark") If places Is Nothing Then TryAddress = False Exit Function //' oops End If If places.Length = 0 Then TryAddress = False Exit Function //' oops End If foundAddrMax = places.Length - 1 //' how many found? If foundAddrMax > 8 Then foundAddrMax = 8 //' but no more than 9 For anum = 0 To foundAddrMax //' and loop through each Set place = places(anum) Set xmlAddr = place.getElementsByTagName("address") Set xmlSuburb = place.getElementsByTagName("LocalityName") Set xmlStreet = place.getElementsByTagName("ThoroughfareName") Set xmlPcode = place.getElementsByTagName("PostalCodeNumber") Set xmlLoc = place.getElementsByTagName("coordinates") //' we MUST find each one of those for an address to be legit If xmlSuburb Is Nothing OR xmlPcode Is Nothing OR xmlLoc Is Nothing Then // ' DEBUG: Response.Write "Abort on NOTHING<br>" TryAddress = False Exit Function //' oops End If // ' and there must be a value in AT LEAST PCode and coordinates for it to be legit If xmlPcode.Length = 0 OR xmlLoc.Length = 0 Then // ' DEBUG: Response.Write "Abort on LENGTH<br>" TryAddress = False Exit Function //' oops End If // ' order of elements in sub array is address, lat, long, street, suburb, pcode aStreet = "" : If xmlStreet.length > 0 Then aStreet = xmlStreet(0).Text aSuburb = "" : If xmlSuburb.length > 0 Then aSuburb = xmlSuburb(0).Text aAddr = "" : If xmlAddr.length > 0 Then aAddr = xmlAddr(0).Text aPCode = xmlPcode(0).Text //' already tested for temp = Split( xmlLoc(0).Text, "," ) //' google gives long, lat, unknown aLong = CDbl( Trim( temp(0) ) ) aLat = CDbl( Trim( temp(1) ) ) //' order of elements in sub array is address, lat, long, street, suburb, pcode addresses(anum) = Array( aAddr, aLat, aLong, aStreet, aSuburb, aPCode ) //' the "best" result is the one that matches the given postcode If aPcode = pcode Then matchPost = anum Next On Error Resume Next xml.Close On Error GoTo 0 TryAddress = True End Function //' back to mainline code //' we test various combos of those values looking for google to find a match //' first of all, street and number are always used: street = num & " " & street & ", " //' first attempt is all those values: address = street & suburb & ", " & city & ", " & state & ", " & pcode & " AUSTRALIA" //'Response.Write "<hr><br>" & address & "<hr>" & vbNewLine //' Response.Flush okay = TryAddress( address ) If Not okay Then //' try omitting the street (legal to omit for this usage) address = suburb & " " & city & ", " & state & ", " & pcode & " AUSTRALIA" okay = TryAddress( address ) End If If Not okay Then //' try omitting the city (legal to omit for this usage) address = street & suburb & ", " & state & ", " & pcode & " AUSTRALIA" okay = TryAddress( address ) End If okay = TryAddress( address ) If Not okay Then //' try omitting the suburb address = street & city & ", " & state & ", " & pcode & " AUSTRALIA" okay = TryAddress( address ) End If If Not okay Then //' assume postcode is bogus? address = street & suburb & " " & city & ", " & state & ", AUSTRALIA" okay = TryAddress( address ) End If If Not okay Then foundAddrMax = -1 //' safety measure! //'Response.Write "<hr><br>The address found is : " & address & "<hr>" & vbNewLine //' so if we found any good addresses, generate the map //' If foundAddrMax >= 0 Then //' move the best match to entry zero, so it shows at top of list If matchPost > 0 Then // ' swap the best match with number 0 temp = addresses(0) addresses(0) = addresses(matchPost) addresses(matchPost) = temp End If //' we center on the best address given (if any) //'Response.Write foundAddrMax & ", " & typename(addresses) & ", " & typename(addresses(0)) & "<HR>" //'Response.Write Join(addresses(0),"::<br>") & "<HR>" centerLat = addresses(0)(1) centerLong = addresses(0)(2) ?> <script src="http://maps.google.com/maps?file=api&v=2&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" type="text/javascript"></script> <script type="text/javascript"> // copy the latitude and longitude arrays here, for the approval process: var latitudes = new Array( ); var longitudes = new Array( ); var mapOkay = false; var markers = new Array(); var googleMap = null; function initMap() { if ( !GBrowserIsCompatible()) { alert("Sorry! Your ancient browser doesn't support Google Maps!"); return; } var map = new GMap2(document.getElementById("GoogleMap")); map.setCenter(new GLatLng(<%=centerLat%>,<%=centerLong%>), <%=ZOOM%>); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); mapOkay = true; googleMap = map; // copy to global! <% ' now we generate as many points as needed For anum = 0 To foundAddrMax row = addresses(anum) ' order of elements in sub array is address, lat, long, street, suburb, pcode addr = row(0) latitude = row(1) longitude = row(2) %> latitudes[<%=anum%>] = <%=latitude%>; longitudes[<%=anum%>] = <%=longitude%>; var icon = new GIcon(); icon.image = "/images/marker<%=(anum+1)%>.png" icon.shadow = "/images/shadow-marker1.png"; icon.iconSize = new GSize(16.0, 33.0); icon.shadowSize = new GSize(33.0, 33.0); icon.iconAnchor = new GPoint(8.0, 30.0); icon.infoWindowAnchor = new GPoint(8.0, 16.0); //icon.iconSize = new GSize(22, 35); /// (w,h) //icon.iconAnchor = new GPoint(11, 36); // (w,h) h=increase to get pin point higher, 20 moves north 20 pixals //icon.infoWindowAnchor = new GPoint(11, 15); // Create a marker whose info window displays its latitude and longitude markers[<%=anum%>] = new GMarker(new GLatLng(<%=latitude%>, <%=longitude%>), icon); // Show info about this marker when it is clicked GEvent.addListener(markers[<%=anum%>], "click", function() { markers[<%=anum%>].openInfoWindowHtml("Address:<br/><%=addr%>"); } ); // and add this marker: map.addOverlay(markers[<%=anum%>]); <% Next %> } // end of the function // function centerMap( lat, lng ) { googleMap.setCenter(new GLatLng(lat,lng)); } // Called when the user approves an address: function approve(which,aNum,aStreet,aSuburb,aPCode) { var suburb_asis = "<%=Trim(suburb_asis)%>"; var pcode_asis = "<%=Trim(pcode_asis)%>"; // if the postcode given by the user was not changed by google, // then accept their word for the suburb: if ( aPCode == pcode_asis ) aSuburb = suburb_asis; var frm = opener.document.featured_ad; frm.addressValidate.value = "1"; frm.latitude.value = latitudes[which]; frm.longitude.value = longitudes[which]; // then utilize the values that Google found: if ( aNum.replace(/\s/g,"") != "" ) frm.share_number.value = aNum; if ( aStreet.replace(/\s/g,"") != "" ) frm.share_street.value = aStreet; aSuburb = aSuburb.replace(/^\+s/,"").replace(/\s+$/,"").toUpperCase(); // trim var sel = frm.share_suburb; sel.selectedIndex = 0; if ( aSuburb != "" ) { for ( var i = 1; i < sel.options.length; ++i ) { var opt = sel.options[i]; if ( opt.text.toUpperCase().indexOf(aSuburb) == 0 ) { sel.selectedIndex = i; // frm.share_postcode.value = opt.value; break; } } } // alert(aSuburb); // alert(aPCode); // and we are done here self.close( ); } </script> </head> <body onLoad="initMap()" onUnLoad="GUnload()"> <div id="GoogleMap" style="width: 390px; height: 300px"></div> <br/> <form style="inline" ID="Form1"> <table style="width: 390px; margin-left: 10px;" border=0 cellpadding=2 class="style2" ID="Table1"> <% ' so...how many address matches did we get?? If foundAddrMax = 0 Then ' just one! So user either approves or disapproves %> <tr> <td colspan=2> Google found that address at the location<br>indicated on the map.<p> If that is correct, then just click the "is Correct" button.<br> If it is not correct, then click on the "Try Again" button.<br> </td> <% Else %> <tr> <td colspan=2 style="padding-bottom: 6px;"> Google found <b><%=(foundAddrMax+1)%> location(s)</b> that match that address.<br/> Click on a numbered marker below to find it on the map.<p> If one of the numbered markers is indicating<br> your actual location, then simply click on the<br> appropriate "is Correct" button.<br> Click on "Try Again" if none are correct. </td> </tr> <% End If For btn = 0 To foundAddrMax row = addresses(btn) ' order of elements in sub array is address, lat, long, street, suburb, pcode address = row(0) lat = row(1) lng = row(2) temp = row(3) spaceAt = InStr( temp, " " ) aNum = "" aStreet = temp ' assume the worst If spaceAt > 0 Then aNum = Left(temp,spaceAt-1) If IsNumeric(aNum) Then aStreet = Mid(temp,spaceAt+1) ' best case: number and street Else aNum = "" ' nope, back to worst case End If End If aSuburb = row(4) aPCode = row(5) url = "javascript:centerMap(" & lat & "," & lng & ");" %> <tr> <td rowspan=2 valign=middle ><a href="<%=url%>"><img src="/images/marker<%=(btn+1)%>.png" border=0></a></td> <td><%=address%></td> </tr> <tr> <td> <? //SET A REPLACE FUNCTION ON ANY POSSIBLE APOSTROPHES aStreet = Replace( aStreet, "'", "" ) aSuburb = Replace( aSuburb, "'", "" ) ?> <input type=button class="sbttnorange" value="Marker <%=(btn+1)%> is Correct" onclick="approve(<%=btn%>,'<%=aNum%>','<%=aStreet%>','<%=aSuburb%>','<%=aPCode%>');"><br> </td> </tr> <? Next Else //' else if foundAddrMax < 0 .... meaning no matches on address ?> <body> <form style="inline" ID="Form2"> Sorry, Google Maps couldn't find that address or variations on it. Try again. <? End If ?> <tr> <td></td> <td style="padding-top: 10px;"> <input type=button class="sbttnorange" value="Close Window Try Again" onClick="self.close();"> </td> </tr> </table> </form> </body> </html> </body> </html>
  6. Hi guys, I'm hoping someone can help out with this one. I need to convert the following code so that the results are displayed in 3 columns. Here's the code. <tr> <td colspan="5"> <% strSQL = "SELECT blah FROM blah ORDER BY blah" RS_open ary = rstDBEdit.getrows%> <table width="100%" border="0" cellspacing="0" cellpadding="0" class="style2"> <%for i=0 to 9%> <tr> <td width="3%" height="18"> </td> <td> </td> <td width="32%"> <input type="checkbox" name="share_category" value="<%=ary(0,i)%>"> <span class="style1"> <%=ary(0,i)%></span></td> <td width="35%"> <input type="checkbox" name="share_category" value="<%=ary(0,i+10)%>"> <span class="style1"><%=ary(0,i+10)%></span></td> <td width="30%"> <input type="checkbox" name="share_category" value="<%=ary(0,i+20)%>"> <span class="style1"><%=ary(0,i+20)%></span></td> </tr> <%next%> </table> <%RS_close%> </td> </tr> The results should be displayed as on this page... http://www.housemates.com.au/placeanad/share_ads/placeanad_create.asp (Underneath Share Features and Preferences)
  7. Hey guys, JS has never been my stronger point, so Im after a bit of help with this bit of code. I have an auto suggest field that is populated by user input. When the user has made their final selection, they click on a button to "verify" this input. In simple terms, here's what might be displayed in the auto suggest field upon user selection. INALA, Queensland 4077; ...and then how its passed over to the verification popup window. suburb=INALA%2C%20Queensland%204077%3B I need to somehow split this up so I get each value separately. eg suburb - INALA state - Queensland pcode - 4077 Here's the existing snippet of JS that captures the user input. var suburb = fixField(form.search.value,0,"suburb"); Thanks!
  8. Aha! I managed to get it sorted out. (using brute force) Thanks to the suggestion made above by psycho. <? echo str_replace("\r\n\r\n", "<div style=font-size:0;height:10px;></div>", $property_description); ?>
  9. Strangely enough the problem goes away when I make the table wider. Urrgh...
  10. Thanks again. That makes sense. (Sorry my background is ASP) I tried the nl2br method and got the same result. You can see the issue I'm faced with here (this is the asp version) in the description. http://www.housemates.com.au/share_ads/share_open.asp?share_ID=7243 It's really annoying.
  11. Thank you. It seems I still have this annoying issue. My text is being displayed like this........ I have a room available in my 2 bed flat in Ashgrove. The flat is in a quiet block of six units and is an older style flat so nice and roomy. The room is unfurnished, but I can source a bed if you need. There is great storage in the room with built in cupboards, and the room is large enough to fit a queen bed, chest of draws and bedside table.
  12. Thank you. Errr....bit more help? <? echo define($property_description, 'vbCrlf', "\r\n"); ?> No?
  13. Hey guys, Can someone tell me what the equivalent of this is in PHP? <%response.write replace(property_description, vbCrlf,"<br>")%>
  14. Where do I put the order by????? $r2=query_wrapper("SELECT * FROM tblphotos ORDER BY tblph_shareID DESC LIMIT 1 WHERE tblph_shareID = ?", $share_ID);
  15. Sorry, I'm working with someone elses code. I'm not sure what the function does.
  16. By the way, I was asking about TOP because I'm trying to conver this MSSQL query. strSQL2 = "SELECT TOP 1 * FROM tblphotos WHERE tblph_shareID = " & SQLNumber(rstDBEdit("share_ID")) & " ORDER BY tblph_ordering ASC"
  17. Would you mind helping me get this query right? My background is ASP/MSSQL. This is what I currently have. $share_ID = $rstDBEdit["share_ID"]; $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ", $share_ID. " ORDER BY tblph_ordering ASC LIMIT 1");
  18. Can someone tell me if this is right? $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?",$rstDBEdit["share_ID"]). " ORDER BY tblph_shareID DESC LIMIT 1"; I'm getting the following error.... Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in (line 35) ....which is if($rstDBEdit2=mysql_fetch_assoc($r2)) Here's the code in it's entirity $r2=query_wrapper("SELECT * FROM tblphotos WHERE tblph_shareID = ?",$rstDBEdit["share_ID"]). " ORDER BY tblph_shareID DESC LIMIT 1"; if($rstDBEdit2=mysql_fetch_assoc($r2)) { $fname = $rstDBEdit2["tblph_filename"]; $id = $rstDBEdit2["tblph_shareID"]; $image = $blogpath.$rstDBEdit["tblph_ID"]."/small_".$fname; $virtualPath = $shareurl.$rstDBEdit["tblph_ID"]."/small_".$fname;
  19. What about this? $timestamp = strtotime($rstDBEdit["share_datecreated"]); $oneweekago = strtotime("-1 week"); if($oneweekago<=$timestamp) { echo "this is a new ad"; } ...can this be written better?
  20. I tried this as a test, but obviously, it's not right. if(strtotime($rstDBEdit["share_datecreated"])<strtotime('-7 days')){ echo "this is a new ad";
  21. Sorry, its a mysql database. rstDBEdit("share_datecreated") is a date field.
  22. Hey guys, Im wanting to have this bit of code rewritten into PHP. It basically checks the date pulled from the DB and if its only 2 days old, it displays a "new listing" image. <%share_newlisting = DateDiff("d", rstDBEdit("share_datecreated"), now()) if share_newlisting < 2 then%> <div style="margin-top:5px"><img src="/images/new_listing.gif" width="81" height="15" align="absbottom"></div> <%end if%>
  23. I'm hoping someone can help me out with this, I'm relatively new to PHP as my background is ASP, so I'm a bit stuck. I'm using the following code as demonstrated here htmlblog.us/jquery-autocomplete ...and I've customized it (slightly) to pull information from my mysql database. Everything is working fine, however, my problem is that when the user selects a specific location from the dropdown, its passing over the suburb, the state, and the postcode. I only want to pass over the postcode value, so I can handle the results easily on the search results page. If I use this.... while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) ) { $data[] = array( 'label' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] , 'value' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] .'; ' ); It posts this to my search results page... (eg showing a search for Brisbane, QLD; 4000) Array ( [zipsearch] => BRISBANE, QLD 4000; ) I only want the postcode value. So instead, I would like ... Array ( [zipsearch] => 4000; ) I tried doing this.... while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) ) { $data[] = array( 'label' => $row['pcode_area'] .', '. $row['pcode_state'] .' '. $row['pcode_postcode'] , 'value' => $row['pcode_postcode'] .'; ' ); ..which passes over just the postcode like I want, but that's no good because upon selection, the suburb and state disappear leaving just the postcode in the selection box, which may confuse people. I'm pretty sure there's an easy way to do this, but being new to PHP, I'm a bit lost. I would really appreciate some help with this, as I'd like to get this sorted ASAP. Thank you. John
×
×
  • 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.