Jump to content

spacepoet

Members
  • Posts

    320
  • Joined

  • Last visited

Everything posted by spacepoet

  1. Thank you for the tip .. I will look at it .. I have found many examples but wanted to see if anyone on here may have done this before and had some PHP code examples ..
  2. Hello: I am trying to figure out how to select all the cities/zipcodes in a radius - say 20 miles - with a zipcode set to a certain one. Say it is 19128 - a Philadelphia zipcode. For now, I just want to use a SELECT Statement, not allowing a user to enter the zipcode and select the mile radius himself or herself. This is my Zipcode database set-up" CREATE TABLE `zip_codes` ( `zip_id` int(11) NOT NULL auto_increment, `zip` varchar(5) NOT NULL default '', `lat` varchar(10) NOT NULL default '', `lon` varchar(10) NOT NULL default '', `city` varchar(50) default NULL, `full_state` varchar(50) default NULL, `abbr_state` char(2) NOT NULL default '', PRIMARY KEY (`zip_id`), UNIQUE KEY `zip_id` (`zip_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=41833 ; -- -- Dumping data for table `zip_codes` -- INSERT INTO `zip_codes` VALUES(1, '00501', '40.92233', '-72.63708', 'HOLTSVILLE', 'NEW YORK', 'NY'); ETC.... I have it in my sitemap.php file (which using mode re-write becomes sitemap.html): <? echo "<ul class='site-map-ul'>"; $query2 = "SELECT zip_id,lat,lon,city,abbr_state,zip FROM zip_codes WHERE abbr_state ='PA'"; $result2 = mysql_query($query2); $num_rows2 = mysql_num_rows($result2); for($j=0;$j<$num_rows2;$j++) { $row2 = mysql_fetch_array($result2); $zip_id = $row2['zip_id']; $city = $row2['city']; $abbr_state = $row2['abbr_state']; $zip = $row2['zip']; $city = ucwords(strtolower($city)); echo "<li class='site-map-ul-li'><a href='$zip_id.$city.$abbr_state.$zip.php?zip_id=$zip_id&city=$city&abbr_state=$abbr_state&zip=$zip' title='".$city." ".$abbr_state.", ".$zip."'>".$city." ".$abbr_state.", ".$zip."</a></li>"; } echo "</ul>"; ?> It is currently getting just records for the state of PA, but I want to use a zipcode .. How do I do this .. ?? Then, I would like to build pages based on the records like: <a href="232432.Philadelphia.PA.19128.html" title="Philadelphia PA,19128">Philadelphia PA,19128</a> which it does, but I have having difficulty trying to get it to transfer to the "proper" site page, myPage.php, which I write into pages based on the page id and myPageURL. I am doing this with an .htaccess file. myPage.php: <?php include("include/db.php"); $con = mysql_connect($db_host, $db_user, $db_password); mysql_select_db($db_table); $zip_id = $_REQUEST['zip_id']; $city = $_REQUEST['city']; $abbr_state = $_REQUEST['abbr_state']; $zip = $_REQUEST['zip']; $id = $_GET['id']; $myPageURL = ""; $myTitle = ""; $myDesc = ""; $myHeader = ""; $mySubHeader = ""; $myPageContent = ""; $myReadMore = ""; $myPageContentMore = ""; $myBannerContent = ""; $photo = ""; if(isset($_GET)) { if($id!="") { $query = "SELECT id, myTitle, myDesc, myHeader, mySubHeader, myPageContent, myReadMore, myPageContentMore, myBannerContent, photo_filename FROM myPageData WHERE id = $id"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); if($num_rows>0) { $row = mysql_fetch_array($result); $continue = true; $myTitle = $row['myTitle']; $myDesc = $row['myDesc']; $myHeader = $row['myHeader']; $mySubHeader = $row['mySubHeader']; $myPageContent = $row['myPageContent']; $myReadMore = $row['myReadMore']; $myPageContentMore = $row['myPageContentMore']; $myBannerContent = $row['myBannerContent']; $photo = $row['photo_filename']; } } } <html> <meta name="description" content="<? echo $myDesc; ?>" /> <title><? echo $myTitle; ?></title> ... </html> .htaccess # Re-writes from myPage.php?id=$id&myPageURL=$myPageURL to 1.This-Is-A-Page.html RewriteRule ^([0-9]+).([a-zA-Z0-9\-]+)\.html$ myPage.php?id=$1&myPageURL=$2 [L] I was trying something like this: RewriteRule ^([0-9]+).([a-zA-Z0-9\-]+).([a-zA-Z0-9\-]+).([0-9]+)\.html?$ sitemap.php?zip_id=$1&city=$2&abbr_state=$3&zip=$4 [NC,L] RewriteRule ^([0-9]+).([a-zA-Z0-9\-]+).([0-9]+).([a-zA-Z0-9\-]+).([a-zA-Z0-9\-]+).([0-9]+)\.html$ MyPage.php?id=$1&myPageURL=$2&zip_id=$3&city=$4&abbr_state=$5&zip=$6 [NC,L] But that is not working at all ... Anyone have any ideas on one or both of these issues .. ?? I am sure I will want to refine this as I progress but for now I would be very happy to get it working as I listed. My idea is to eventually add a new field to the "zip_codes" table called "search_term", and assign unique terms to all zipcodes in the radius: Select all for first term: <a href="Music.Lessons.232432.Philadelphia.PA.19128.html" title="Music Lessons Philadelphia PA,19128">Music Lessons Philadelphia PA,19128</a> <a href="Music.Lessons.232433.Philadelphia.PA.19127.html" title="Music Lessons Philadelphia PA,19127">Music Lessons Philadelphia PA,19127</a> Etc.. Then do a new term: <a href="Guitar.Lessons.232432.Philadelphia.PA.19128.html" title="Guitar Lessons Philadelphia PA,19128">Guitar Lessons Philadelphia PA,19128</a> <a href="Guitar.Lessons.232433.Philadelphia.PA.19127.html" title="Guitar Lessons Philadelphia PA,19127">Guitar Lessons Philadelphia PA,19127</a> Etc.. Any ideas .. ?? Thanks, as always!
  3. Wait, I think you mean instead of having 4 fields named myPagNav1, myPagNav2, myPagNav3, and myPagNav4 in the database I should instead have 1 field named myPagNav (or as you listed it "type") and the code should then work, right? I originally had it this way (1 field with 4 radio button options), but since it was not working I changed to 4 fields selectable by checkboxes. I can easily change it back if you think that is all I need to do. Please confirm. Thanks again.
  4. Hi everyone: Thanks very much for the input and coding help! I appreciate it. @PFMaBiSmAd: Thanks for posting that code. I was going to try to add it to my page and see how I make out, but I Just noticed your post right under it. Question: will the code not work until I revise my database design? I need to move forward to finish this project, but I also want to work on the page to make the code "better" as per your proposed idea. Which I can do on another server. Let me know. Thanks!
  5. I tried this: <? $sql = "SELECT id, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav4='4' AND myPageActive='Yes' ORDER BY listorder"; $res = mysql_query($sql); if ($res) { if (mysql_num_rows($res)) { echo "<ul class='mm-footer-ul'>"; while ($row = mysql_fetch_assoc($res)) { echo "<li class='mm-footer-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } mysql_free_result($res); echo "</ul>"; } } ?> But it is selecting records from the other areas of the site. I assume the way I posted is the only way to get it to work .. ?? I just want to learn to make my code cleaner and more efficient .. This is the whole page: <?php include("include/db.php"); $con = mysql_connect($db_host, $db_user, $db_password); mysql_select_db($db_table); $id = $_GET['id']; $myPageURL = ""; $myTitle = ""; $myDesc = ""; $myHeader = ""; $mySubHeader = ""; $myPageContent = ""; $myReadMore = ""; $myPageContentMore = ""; $myBannerContent = ""; $photo = ""; $continue = false; if(isset($_GET)) { if($id!="") { $query = "SELECT id, myTitle, myDesc, myHeader, mySubHeader, myPageContent, myReadMore, myPageContentMore, myBannerContent, photo_filename FROM myPageData WHERE id = $id"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); if($num_rows>0) { $row = mysql_fetch_array($result); $continue = true; $myTitle = $row['myTitle']; $myDesc = $row['myDesc']; $myHeader = $row['myHeader']; $mySubHeader = $row['mySubHeader']; $myPageContent = $row['myPageContent']; $myReadMore = $row['myReadMore']; $myPageContentMore = $row['myPageContentMore']; $myBannerContent = $row['myBannerContent']; $photo = $row['photo_filename']; } } } if(!$continue) { header("location:1.Homepage.html"); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta name="description" content="<? echo $myDesc; ?>" /> <title><? echo $myTitle; ?></title> </head> <body> /* TOP NAVIGATION */ <? $query = "SELECT id, myPageNav1, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav1='1' AND myPageActive='Yes' ORDER BY listorder"; $result1 = mysql_query($query); $result2 = mysql_query($query); $num_rows = mysql_num_rows($result2); { $row1 = mysql_fetch_array($result1); $myPageNav1 = $row1['myPageNav1']; if ($myPageNav1 != "") { echo "<ul class='mm-side-ul'>"; } for($j=0;$j<$num_rows;$j++) { $row2 = mysql_fetch_array($result2); $id = $row2['id']; $myPageURL = $row2['myPageURL']; $myButtonTitle = $row2['myButtonTitle']; $myTitle = $row2['myTitle']; echo "<li class='mm-side-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } if ($myPageNav1 != "") { echo "</ul>"; } } ?> <header class="mm-header mm-replace"> ... </header> <div class="content-container"> <article class="mm-article"> /* LEFT NAVIGATION */ <? $query = "SELECT id, myPageNav3, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav3='3' AND myPageActive='Yes' ORDER BY listorder"; $result1 = mysql_query($query); $result2 = mysql_query($query); $num_rows = mysql_num_rows($result2); { $row1 = mysql_fetch_array($result1); $myPageNav3 = $row1['myPageNav3']; if ($myPageNav3 != "") { echo "<ul class='mm-side-ul'>"; } for($j=0;$j<$num_rows;$j++) { $row2 = mysql_fetch_array($result2); $id = $row2['id']; $myPageURL = $row2['myPageURL']; $myButtonTitle = $row2['myButtonTitle']; $myTitle = $row2['myTitle']; echo "<li class='mm-side-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } if ($myPageNav3 != "") { echo "</ul>"; } } ?> </article> </div> <footer class="mm-footer"> /* FOOTER NAVIGATION */ <? $query = "SELECT id, myPageNav4, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav4='4' AND myPageActive='Yes' ORDER BY listorder"; $result1 = mysql_query($query); $result2 = mysql_query($query); $num_rows = mysql_num_rows($result2); { $row1 = mysql_fetch_array($result1); $myPageNav4 = $row1['myPageNav4']; if ($myPageNav4 != "") { echo "<ul class='mm-footer-ul'>"; } for($j=0;$j<$num_rows;$j++) { $row2 = mysql_fetch_array($result2); $id = $row2['id']; $myPageURL = $row2['myPageURL']; $myButtonTitle = $row2['myButtonTitle']; $myTitle = $row2['myTitle']; echo "<li class='mm-footer-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } if ($myPageNav4 != "") { echo "</ul>"; } } ?> </footer> </body> </html> - All the records come from 1 table - myPageData. - I allow the user to check 1 of 3 areas to assign the menu area (myPageNav1, myPageNav2, myPageNav3) - I also allow the user to check a box (myPageActive); if it is check it equals "Yes" and the page displays Any ideas on how to make this code better .. ?? The way I posted it is the only way I have been able to get it to function properly .. Thanks.
  6. Hi: The way I posted it is the only way I have been able to get it to work, but I do agree I should not be using a query twice. So, what you posted should do the trick for me (if I add my code I posted, or course), ?? Thanks much!
  7. Hi - OK, so I did get it to work! Which is good 'cause this was drivin' me nuts. Thanks much for helping me think in a different way. However, it seems a bit messy. I think the code could be cleaner. <? $query = "SELECT id, myPageNav4, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav4='4' AND myPageActive='Yes' ORDER BY listorder"; $result1 = mysql_query($query); $result2 = mysql_query($query); $num_rows = mysql_num_rows($result2); { $row1 = mysql_fetch_array($result1); $myPageNav4 = $row1['myPageNav4']; if ($myPageNav4 != "") { echo "<ul class='mm-footer-ul'>"; } for($j=0;$j<$num_rows;$j++) { $row2 = mysql_fetch_array($result2); $id = $row2['id']; $myPageURL = $row2['myPageURL']; $myButtonTitle = $row2['myButtonTitle']; $myTitle = $row2['myTitle']; echo "<li class='mm-footer-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; } if ($myPageNav4 != "") { echo "</ul>"; } } ?> Is there a more streamlined way to do this, based on what I posted .. ??
  8. Hi again. Thanks for the input. "Opening tag goes before the loop, closing tag after." Can you show me what you mean, based on my code .. ?? I am not sure I follow. Also, for what you posted, can you show me an example ..?? I kind of follow you but not exactly... The help is much appreciated - I thought I had programmed myself into a corner!
  9. I should note that I have 4 sections like this for the top nav, middle nav, left nav, and footer (which this is). They are all mostly the same except for: myPageNav1 = top nav myPageNav2 = middle nav myPageNav3 = left nav myPageNav4 = footer nav
  10. I have tried that .. the problem then is if the pages in that section are not active (myPageActive is not "Yes"), I get an empty set of ULs displaying: <ul class='mm-footer-ul'></ul> That is not semantically properly, either. I don't want that, either. Any other ideas .. ??
  11. Hi: I am trying to figure out how to display a beginning UL tag and an ending UL tag only once when it is in a loop. This is what I have: <? $query = "SELECT id, myPageNav4, myPageURL, myButtonTitle, myTitle FROM myPageData WHERE myPageNav4='4' AND myPageActive='Yes' ORDER BY listorder"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); for($j=0;$j<$num_rows;$j++) { $row = mysql_fetch_array($result); $id = $row['id']; $myPageNav4 = $row['myPageNav4']; $myPageURL = $row['myPageURL']; $myButtonTitle = $row['myButtonTitle']; $myTitle = $row['myTitle']; echo "<ul class='mm-footer-ul'>"; echo "<li class='mm-footer-ul-li'><a href='$id.$myPageURL.html' title='".$myTitle."'>".$myButtonTitle."</a></li>"; echo "</ul>"; } ?> The problem is that every LI is getting a set of UL tags: <ul> <li><a href="Page-One.html" title="Page One">Page One</a></li> </ul> <ul> <li><a href="Page-Two.html" title="Page Two">Page Two</a></li> </ul> Instead of: <ul> <li><a href="Page-One.html" title="Page One">Page One</a></li> <li><a href="Page-Two.html" title="Page Two">Page Two</a></li> </ul> I only want to display the data if myPageNav4 is "4" and myPageActive is "Yes", which it currently does. I want to keep the ULs inside the loop that checks that these two conditions are true, but will still write the UL list properly. How can I do this?? I am totally stumped and need some fresh eyes. Thanks!
  12. OK .. thank you for that .. Can you show me an example of what you mean by escaping the data ... ??
  13. Is this: $myData = mysql_real_escape_string($_POST['myData']); secure enough .. ??
  14. Because the person I am doing this for wants to be able to copy and paste affiliate-like ads and display them on his site .. The code generated comes with markup ... This isn't a public form; it is in an admin area .. but I am trying to make it as safe as possible .. I assume this is not possible (the way I was trying to do it) .. ??
  15. Hello: I have been replacing all " (quotes) with this: " I was under the impression I should do this when inserting data into a database. This works, but when I select the data and display it like this: <a href="http://www.website.com">Website</a> The link does not work. Should I be doing it the "standard" way: <a href="http://www.website.com">Website</a> ??? I thought the idea was to remove the " and ' for security reasons .. ?? What am I missing .. ??
  16. Thanks for the idea! I will give this a shot. No, I do not have a page for every location - I am testing different ideas. The idea is to use my ZipCode database and use mod re-write; like I do in other projects.
  17. Hello: I am trying to redirect a user from one page when they click a link, and carry them to a new page with the session (or variable?) from the first page. I cannot seem to get this to work. What am I doing wrong. The idea is a user clicks a link like this: <a href="philadelphia-pa-19128.php">Philadelphia, PA 19128</a> Which goes to philadelphia-pa-19128.php: <?php $myLocation = "Philadelphia, PA 19128"; header('Location: locations-page.php'); ?> <html> ... </html> Then the header would - I thought, incorrectly - take them to a new page and print the location: <?php ?> <? $myLocation = $_REQUEST['myLocation']; ?> <html> <? echo "myLocation" ?> </html> This is not working ... How can I accomplish this? Thanks!
  18. Hello: I am currently using this method to make sure all apostrophe/quotes characters entered into my Rich Text Editor get displayed properly - meaning they do not get stripped away of have a "\" slash added to them: add-page.php include("../include/mm-code-lib.php"); ... $myPageContent = mysql_real_escape_string(str_replace(array('\'', '"'), array(''', '"'), $_POST['myPageContent'])); ... mm-code-lib.php if(get_magic_quotes_gpc()) { $_POST = array_map('stripslashes',$_POST); $_GET = array_map('stripslashes',$_GET); $_COOKIE = array_map('stripslashes',$_COOKIE); } Is there a cleaner/better way to do this? I am use the FCK Editor, which sometimes seems to overwrite how a user enters text, and this is the only way so far I have been able to make it work. Thanks!
  19. Thank you! I had to tweak this one line so it is now like this: echo "<option value='{$row['shout_id']}'>{$row['shout_photo_caption']}</option>"; but now works fine! I appreciate the help.
  20. Hello: I am trying to make a dynamic select menu, but can not seem to figure out what I am doing wrong. The idea is to select the list in the database (spon_id and shout_photo_caption) and display the list as an HTML select menu. Plus to have the database "remember" what selection was picked the last time the user used the select menu and inserted it into the database. I am a bit stuck ... Here is what I have: <? $query = "SELECT shout_id, shout_photo_caption FROM myShoutout ORDER BY shout_listorder"; $result = mysql_query($query); $num_rows = mysql_num_rows($result); echo '<select>'; while ($num_rows = mysql_num_rows($result)) { echo '<option value='" . $row['shout_id'] . '">' . $row['shout_photo_caption'] . '</option>'; } echo '</select>'; ?> What am I missing .. ??
  21. Hi there: Thanks for the tip. I must admit I have not heard of this, but certainly willing to try it out and see if it is a better solution. Thanks!
  22. Thank you! For the explanation and the code example - everything works fine now!
  23. Hi: I have this code snippet here: echo "<iframe frameborder='0' width='640' height='700' src='calendar.php?month='.date('n').'&year='.date('Y').''></iframe>"; Can't for the life of me figure out how to get it to write the month and the year onto it. The idea is, a user clicks a link on the menu called "Calendar", and he/she is taken to the calendar section (HTML page). There is the text, and then the calendar.php page is pulled into the page via the IFRAME. I just can't seem to get it to write the month and year properly, like this: <iframe frameborder='0' width='640' height='700' src='calendar.php?month=7&year=2012'></iframe> Any ideas? This one is frustrating me .. Thanks!
  24. Hi again: Sorry, my mistake on one thing: the form fields are NOT clearing out the data, but everything else is as I listed it. I know all the database fields, login credentials are correct. This worked fine until I got the error message about those function no longer being valid. I do have the info added to the php.ini file, but no errors are displayed. This is hosted on one of GoDaddy's unlimited plans, where there is one main domain/site in the root folder, and all the other sites - such as the one in question - are build in subfolders. Maybe that's a cause? The site use to be in the root of its own hosting package. Is it time for a new login script ?? This is my friend's site, so for once I'm not rushed to find a solution ..
  25. The form mark-up is really just this (with the styling DIVs removed): <form id="form1" name="form1" method="post" action="<? echo $PHP_SELF; ?>"> <input name="myUserName" type="text" id="myUserName" size="40" /> <input name="myPassword" type="password" id="myPassword" size="40" /> <input name="Login" type="submit" id="Login" value="Login" /> </form> Can you recommend a better way, based on your comments about sanitation of data? I have been reading a book on PHP, but I am not there yet in terms of fully understanding what is modern and what is old ...
×
×
  • 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.