Jump to content

tec-4

Members
  • Posts

    36
  • Joined

  • Last visited

    Never

Everything posted by tec-4

  1. Hi Everyone, If I had an index covering multiple columns would I need to have a separate single column index for the "root" column? Or does it being the main column in the multi-column index work just as well? For example, say i have the following index on these columns, and in this order: (County, Status, Type, SubType) Would having a single column index on County be of any benefit or simply a waste of space? Please let me know if I need to elaborate further or if more info is needed to make a correct decision. Thanks for the help!
  2. Well that was a quick fix...and here I thought I was going crazy Thanks for looking it over xyph!
  3. Hello, Currently have an array like looks like the following when using print_r($session->items): Array ( [F1225] => 1 [EDS11147317] => 1 [1156D6RE001] => 1 [i111ADE47946] => 1 [s679AQ339] => 1 [s67914599] => 1 [CH111337631254] => 1 [s6787903647] => 1 [A11144O189] => 1 [F11144520] => 1 [121584Q12] => 1 [i11144661ADE] => 1 [s678829NB] => 1 ) I am trying to check if an item is in the array and if so, display a different result but currently every item says it is in the array when they are not (unless my logic is off...from the items I am looking at some should be included and some should not..but the below code is showing every item as having the same result). Example: foreach ($items as $item) { if (in_array($item->ItemID, $session->items)) { //$session->items is the array output above echo "In Array"; } else { echo "NOT in Array"; } } Currently everything say "In Array" when some should not. Am I using the in_array incorrectly? Thanks Everyone.
  4. Gotcha. Didn't seem to work with the double quotes, tried escaping them w/ still no luck but when I put them in single quotes it seemed to do the trick. Thanks for the help Adam!
  5. Hello Everyone, Have 2 links on a page that I am trying to manipulate to do the same thing (add a bookmark to a database). The first link below works fine and adds the bookmark if it is not currently in the DB and notifies you if it is in the DB....the other one, with the slight modifications does not seem to do anything that I can notice and shows no response and does not add the bookmark to the DB...perhaps what I am trying to do is not valid JS.... What I have thus far: This one works: <a href="javascript:(function(){var jsScript=document.createElement('script'); jsScript.setAttribute('type','text/javascript'); jsScript.setAttribute('src', '/bookmark.php?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)); document.getElementsByTagName('head')[0].appendChild(jsScript); })();">Bookmark this!</a> This one does not work: -the only difference is that I replaced the "location.href" with an actual URL and the "document.title" with a title name. <a href="javascript:(function(){var jsScript=document.createElement('script'); jsScript.setAttribute('type','text/javascript'); jsScript.setAttribute('src', '/bookmark.php?url='+encodeURIComponent(http://example.com)+'&title='+encodeURIComponent(Add Me)); document.getElementsByTagName('head')[0].appendChild(jsScript); })();">TEST ME - Bookmark this!</a> I also tried it without the encodeURIComponent and still did not seen to take. Is what I'm trying to do not valid? Essentially trying to make it so that I can place more than one of these links on a page and bookmark a specific item and not the actual page that I am currently viewing.
  6. Sounds good. Thanks again. Apparently been a long day...took me like 10 minutes to find that darn Topic Solved button! lol
  7. Ah! Yes, that makes a lot of sense...it is working now. Still trying to wrap my head around quite a bit of this stuff lol Thanks for the help, AyKay47!
  8. Oh, okay - my bad for the typo...thanks for the catch, though. Maybe it is returning but perhaps I just may not be handling it correctly? Essentially what I am trying to do is process that query and return the correct message to a script that will in turn take the $message and hand it off to a JavaScript function and echo it like so: <?php //connect to database class, process query and return message $db->addNewBookmark($hash,$url,$title,$current_user); ?> /* JavaScript Code */ function displayMessage(str) { // Using pure JavaScript to create and style a div element var d = document.createElement('div'); with(d.style) { // Applying styles: position='fixed'; width = '350px'; height = '20px'; top = '50%'; left = '50%'; margin = '-30px 0 0 -195px'; backgroundColor = '#f7f7f7'; border = '1px solid #ccc'; color = '#777'; padding = '20px'; fontSize = '18px'; fontFamily = '"Myriad Pro",Arial,Helvetica,sans-serif'; textAlign = 'center'; zIndex = 100000; textShadow = '1px 1px 0 white'; MozBorderRadius = "12px"; webkitBorderRadius = "12px"; borderRadius = "12px"; MozBoxShadow = '0 0 6px #ccc'; webkitBoxShadow = '0 0 6px #ccc'; boxShadow = '0 0 6px #ccc'; } d.setAttribute('onclick','document.body.removeChild(this)'); // Adding the message passed to the function as text: d.appendChild(document.createTextNode(str)); // Appending the div to document document.body.appendChild(d); // The message will auto-hide in 3 seconds: setTimeout(function(){ try{ document.body.removeChild(d); } catch(error){} },3000); } <?php // Adding a line that will call the JavaScript function: echo 'displayMessage("'.$message.'");'; } ?> The query runs and seems to process correctly but the $message in the last couple lines (echo 'displayMessage("'.$message.'");' does not seem to echo the message but the JS pop-up will still occur....however, if I just put the straight query in this page itself, like so: mysql_query(" INSERT INTO bookmarks (hash,url,title,username) VALUES ( '".md5($_GET['url'])."', '".$_GET['url']."', '".$_GET['title']."', '".$current_user."' )"); $message = ''; if(mysql_affected_rows($link)!=1) { $message = 'This URL already exists in the database!'; } else $message = 'The URL was shared!'; it will show the appropriate message in the JS popup. Do I need to "hand it over" in a different way or something? Thanks for the help and hope the above makes sense.
  9. Hello everyone, Pretty much what I am trying to do is run a query and based of the queries result, return a string - as of now it is turning up blank and cant seem to pass any strings through the function. Current function: function addNewBookmark($hash,$url,$title,$username){ $query = "INSERT INTO bookmarks (hash,url,title,username) VALUES '".md5($hash)."', '".$url."', '".$title."', '".$username."')"; $result = mysql_query(query, $this->connection); $message = ''; if(mysql_affected_rows($this->connection)!=1) { $message = 'This URL already exists in the database!'; return $message; } else $message = 'The URL was shared!'; return $message; } The above code seems to run fine, just cant seem to pass a string...read that you can possibly use a __toString function? but that keeps throwing errors when I try to work with it. Thanks all!
  10. I have a script that seems to work well to insert a bookmark into a users database when he/she is logged into the system but I am having a hard time figuring out how I would go about making a work-a-round for having an item selected before being logged in, and inserted after they have logged in or registered. For example, I would like a user to be able to select an Item to add to bookmark whether that user is logged in/registered or not and if they are not, they would be greeted with a login/registration form and after successful login the add bookmark script would be initiated on the item previously selected. What I've got this far: Simple form to add bookmark: <form name="bm_table" action="add_bms.php" method="post"> <input type="text" name="new_url" value="http://" /> <input type="submit" value="Add Bookmark"/> </form> Then I have the add bookmark script: BEGIN php $new_url = $_POST['new_url']; try { check_valid_user(); //cannot get past this part since it ends the script....code below if (!filled_out($_POST)) { throw new Exception('Form not completely filled out.'); } // check URL format if (strstr($new_url, 'http://') === false) { $new_url = 'http://'.$new_url; } // check URL is valid if (!(@fopen($new_url, 'r'))) { throw new Exception('Not a valid URL.'); } // try to add bm add_bm($new_url); echo 'Bookmark added.'; // get the bookmarks this user has saved if ($url_array = get_user_urls($_SESSION['valid_user'])) { display_user_urls($url_array); } } catch (Exception $e) { echo $e->getMessage(); } END php Checking valid user - the portion I cannot get past in the above script: function check_valid_user() { // see if somebody is logged in and notify them if not if (isset($_SESSION['valid_user'])) { echo "Logged in as ".$_SESSION['valid_user'].".<br />"; } else { // they are not logged in do_html_heading('Problem:'); echo 'You are not logged in.<br />'; do_html_url('login.php', 'Login'); do_html_footer(); exit; } } How would I go about modifying the script so that a user could fill in the form (later it would be a link...obviously they probably wouldn't be filling in a form that is log-in specific - but same concept I think) Thanks in advance for the help! tec4
  11. Okay, great. That is actually seeming to work really well - just have to tack on an extra 2 hrs to accommodate for timezones but that didn't take too long to figure out. Thanks for the help, Pikachu
  12. To start, I am trying to compare two timestamps: 1) one that is in my database and formatted like 2011-10-11 09:43:17 2) another that I am trying to specify for the current date and time but subtracting 3 hours Essentially I am trying to pull items in my database that are newer than 3 hours old. I think the best way to compare them is by converting both into unix timestamps, but that is where I am having the difficulty and it does not seem to be comparing as it should. What I have now: //define current date in same format as in the DB (this step is probably not needed) $date = date('Y-m-d H:i:s'); //convert to unix timestamp and subtract 3 hours... this comes out to something like 1325288942 $ago = mktime($date) - 10800; //MySQL Query $sql = "select distinct Item from `database`.`table` WHERE UNIX_TIMESTAMP(EntryDate) >= '$ago'"; When I run this query it does not seem to pull any items, even if I subtract multiple days off of the $ago variable. However if I switch it to less than or equal to it pulls up all items...so not sure if my logic is off a bit or something. Thanks for the help!
  13. sorry, its taken me so long to get back to this - been out of town, anyways thank you all for your responses. @ btherl, sorry, that was a type. Supposed to be "$property->zipcode" @xyph - don't think i can use print_r() on it since all the properties are in a database (could be wrong tho, fairly new to the game). But essentially I have thousands of "properties" in a database where i'd like to find unique instances of values within those properties (columns in the DB), such as the zip codes. @msaz87 - I'll have to look into the array_unique() function, havent used that before - I'll definitely be looking into it, thanks for the suggestion.
  14. Hi All, I essentially am trying to figure out how to print out all of the zip codes that are associated with a search that I am doing, but not list the same zip code more than once. My current foreach statement is as follows and prints out the zip code for each property that is associated with the search: <ul> <?php foreach($properties as $property) { ?> <li><?=$property->$zipcode?></li> <?php } ?> </ul> How would I modify this to print out 1 occurrence of each zip code that is in the search, even if, for example 20 properties have the same zip code? Thanks in advance! P.S. - Tried using an array to work with it but pretty sure my logic was incorrect when putting it together and couldn't get past the errors. Anyways, thanks in advance for the help!
  15. Hi all, Trying to figure out why the page I'm creating works when I place a trailing slash but 404's when i take it off...trying to get it to not have it. For example, this code: RewriteRule ^([A-Za-z0-9\-+\(\)#%|_,]+-test-page)([A-Za-z0-9\-/+_\(\)]+)$ file.php?city=$1&query=$2 [L] results in: example DOT com/city-test-page/ and if I take off the trailing slash it goes to a 404 but would like it to be the other way around. Also when I take the "([A-Za-z0-9\-/+_\(\)]+)" and "&query=$2" out it works correctly in regards to trailing slash but they query doesn't work. Any thoughts?
  16. Well, really trying to somehow pass a page specific php variable to a javascript variable so that the "/test.php" in the following code can somehow be dynamic per page. For example, I have a main JS file with: $("#sort_by").change(function() { url = $("#url").val(); window.location = "/test.php" + url + $("#sort_by").val(); }); and am trying to replace the "/test.php" with a url that is page specific to the page, like "/this-page.php" and was wondering if I could define a php variable like $variable = "/this-page.php" in my php file and somehow have my JS file reference this variable. Have tried things like this: $("#sort_by").change(function() { url = $("#url").val(); window.location = "<?php echo $variable; ?>" + url + $("#sort_by").val(); }); but not having any luck...pretty new to JS so not really sure how make them function together. But trying to have my .php page define a variable, call it from another page, and have my JS package it and make it function when I want to sort my page. Does this make more sense? Thanks!
  17. Hi everyone, I'm curious if there is a way to reference a php variable in my js code (essentially replacing the "#sort_by", or at least the "/test.php" in the following code. The code below works great for sorting currently using a select box but I am trying to utilize this same approach for a couple hundred pages and don't deem it practical to make one of these pieces of code per page. Is there any way to reference a page specific variable that I can create per page, such as the URL (/test.php) that I can define and have my JavaScript utilize it? I've tried a couple ways but seem very hacky. $("#sort_by").change(function() { url = $("#url").val(); window.location = "/test.php" + url + $("#sort_by").val(); }); Thanks in advance!
  18. Welcome to PHP Freaks, Panda!
  19. Oh okay, that makes a lot of sense. When I was reading they only briefly glazed over the topic without much explanation. So, I really appreciate both of your input. Thanks you two!
  20. Quick Question: What does it mean to be outside of the web document tree and why is it such a good place to store info? Have been reading through my first PHP book and it references this quite often but I don't think I fully understand it.
  21. tec-4

    hello freaks

    Hello Turk, welcome to the forum. I'm up in the OC, so not too far away. See you around the board here soon.
  22. I've been using PHP Designer for a little while and think it works pretty well. Was using notepad++ but not really a fan for php...think there are some addons I could get for it, but haven't looked into that yet.
  23. Howdy! Welcome to the board!
  24. Oh okay, well that make sense. Was I supposed to pop that in as is or did I need to modify it at all? When I tried the code above and when trying to access the homepage of the website it showed a 500 Internal Server Error.
  25. When placing those 4 lines, as is, in the file and try to load the site (on any webpage, including homepage) it says: "Internet Explorer cannot display the webpage" I then attempted to play around with the commenting of certain lines and when I commented out everything except the last line it shows: 500 Internal Server Error and when commenting out everything, other than the 3rd line down (second from the bottom) it appends the .php to the files like so: /buying.php but goes to the 404 error page.
×
×
  • 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.