Jump to content

oskom

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by oskom

  1. Actually, I was hoping to pass the cookie directly to php and have it build the initial page. After that point the ajax would do the rest. Thanks for the info!
  2. I just checked it out online. Yes, it looks like javascript. Not sure what the difference is yet, though. However, in thinking about it some more, I don't know that the cookie is the solution either. You would have to establish the browser-side cookie with javascript first, then redirect the page(cookie in place) to a PHP page. With Google-searchability at stake, is the googlebot going to be able to take that step? Or does that small amount of javascript intervention break the deal?
  3. aleks, gotta claim ignorance on this: what is ecma?
  4. That was my thinking, which is fine. I would be nice to avoid that step, but if it works, hoooooray!!!
  5. $hash = substr(strrchr('#', $_SERVER['REQUEST_URI']), 1); DarkWater, In testing, it doesn't appear that $_SERVER['REQUEST_URI'] passes the hash. Otherwise, yes, that would be my method. Unfortunately, PHP isn't getting a hash to sub-string. hmmmmmm...
  6. That's exactly what I'm trying to avoid. I don't want to pass it as a variable. This is for an all AJAX site where the unique url's(in theory) will be created in the hash. I can create a particular page from javascript with the hash, but I need to do it with PHP instead...Google searchable!!!! The only way I can make a unique url for each page(i.e. effect the address without actually flipping the page) is to hash it with javascript. I need to then be able to cut-n-paste that url with the hash into another browser window and have PHP build the page based on the hash being turned into a variable PHP can use. I hope that wasn't too confusing. Can I achieve that with PHP? Here's an idea: can I cookie the hash and pass that?
  7. Hey all, Is there some $_SERVER method, or anything else, that will allow PHP to get the hash from a url? In other words, I want to take a url like "www.mydomain.com/#1234" and have PHP get the hash and use it as a variable for other purposes. Does this sound do-able?
  8. sasa, paul2463...I figured out from sasa's function that you can boil the whole thing down. from this: if(array_get_key_index($arr, $var) !== false) echo array_get_key_index($arr, $var); else echo 'err'; function array_get_key_index($arr, $var){// first index is 0 if (!is_array($arr)) return false; $a = array_keys($arr); return array_search($var, $a); } to this: echo array_search($var, array_keys($arr)); Obviously, I took out the error checking, but for simplicity's sake, this actually works better for my purposes. Thanks, people.
  9. Thanks, sasa & paul2463. Both methods worked! I'll flip a coin to see who wins the giant stuffed teddy bear... (time passes) It was sasa!! *NOTICE: All claims that someone will win a teddy bear are completely false. Any promises of cuddly toys should be excused as a fabrication of a pathological mind.
  10. Well, that's not what I'm looking for. I'm searching for the order of the KEY, not the value. In other words, if I've got a variable named "pickles" and an array where the key of the 3rd item in the array is "pickles", I want the function to compare the variable and the array and tell me that my variable corresponds with the key of item number 3. It should assume that I don't know the value of that array item. Does that make sense? sasa, I may have posted this after your post. I'll test your function and see if it's the winner.
  11. Hello all, I've been combing the array pages of php.net with no answer to my question, so here it is... Is there a method for getting a numeric index of a text key in an array given a corresponding variable? Here's an example: $arr = array("first" => "apples", "second" => "oranges", "third" => "bananas"); $var = "second"; //THIS IS A MADE-UP FUNCTION NAME, OBVIOUSLY... array_get_key_index($arr, $var); //THE DESIRED RESULT WOULD BE 2...OR MAYBE 1 IF YOU'RE ASSUMING STANDARD ARRAY INDEXING, BUT YOU GET THE IDEA. Is there a php function that gives this kind of result?
  12. GingerRobot...your function is actually EXACTLY what I needed! It needs a little tweaking for presentation, but it really DID work. Thanks!
  13. I like the menu function you've got there. It's not EXACTLY what'll do the trick but it's darn close! Just to clarify, Gingerroot, the displayOrder is the "presentation" order. This is to give the site administrator the opportunity to order the links in whatever way they'd like. Also, here's the db table structure: To clarify this, the links "Neural & Me", "Professionals", and "About" are level 1 navigation items, hence the parentID of those being 0. You'll notice that the(obviously BS) items of "harry" and "mary" have a parentID of 3 which is the ID of "Neural & Me"...that's the relationship. What might augment what you've done with the menu function is to do a query for the sub-levels inside the loop(?). In other words, maybe I should start with a query that just pulls the top level links, loop through those and invoke the menu function inside that loop to pull the sublevels...does that make sense?
  14. Hello all, I'm trying to take the results of a mysql query from a single table with data that needs to be sorted very carefully afterward based on certain parameters. The way I came up with is to organize data of a specific type into arrays to be sorted through again later. However I'm not quite sure of the method for taking the data from a query and then looping through it to stick it into another array. Here's the crux of what I'd like to do: $result = mysql_query("SELECT * FROM table"); //MAYBE ESTABLISHING THE ARRAYS LIKE THIS? $set1 = array(); $set2 = array(); $set3 = array(); $counter = 0; while($row = mysql_fetch_array($result)) { $data = $row['data']; if($data == 1) { $set1[$counter]; = $data; } else if($data == 2) { $set2[$counter]; = $data; } else { $set3[$counter]; = $data; } $counter++; } Am I on the right track here? If it helps, here's what I'm doing with this: I'm trying to build a tree-structure type navigation with multiple levels. Each row in the db has these params:ID, parentID(if it's a sublevel item, this is the ID of the item it's relative to), text(of the link), URL(of the link), level(in the structure), displayOrder(relative to its' level). I want to pull out all the data ordered by displayOrder, then sort each of them into an array based on it's level and its' parentID if it's not level 1. THE CAVEAT: My only problem with this concept is that it sets me up with a mess of loops, the number of which is predefined. I'd rather have a recursive function that will run until the max number of levels is reached, given the idea that each set of navigation links may have a varied amount of levels. So perhaps I've got 2 questions: 1. How do you do the loop thing I've described? 2. Should I do the loop thing I've described in THIS case based on the desired output? (Wow! This is complicated stuff.) Enlightenment?
  15. I can only reassert: I've already done all of those things already!!!! Rewriting the code(as I have just done to test it) like this... $result = mysql_query("SELECT * FROM table WHERE ID = ".$_REQUEST['ID']."") or die("Problem with the query: $q<br>" . mysql_error()); $row = mysql_fetch_array($result); //LINE OF CODE IN ERROR ...will display no errors on the page itself. I get the data I wanted just fine. Whether or not the "die()" statement exists after the query seems to be irrelevant, which says to me that the query is fine. The more telling thing is that I'm actually GETTING DATA! MySQL likes my query enough to give me the data but PHP gets all persnickety about something.
  16. Hello all, I've been surfing forum threads on this, and there are plenty, with no satisfactory results. Here's the deal... I've got quite a few instances of this very common query code on my site: //example 1 $result = mysql_query("SELECT * FROM table WHERE ID = ".$_REQUEST['ID'].""); $row = mysql_fetch_array($result); //LINE OF CODE IN ERROR //example 2 $result = mysql_query("SELECT * FROM table WHERE ID = ".$_REQUEST['ID'].""); while($row = mysql_fetch_array($result)) { //LINE OF CODE IN ERROR //LOOP DATA } The PHP error log will frequently give a warning to this effect:"PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/ftp/path/to/file.php on line 15". The important thing to know is that I ALWAYS get the desired result from the database. I've added "or die(mysql_error())" to the end of the queries with no error being displayed and echoing the $result will always give me the resource id number. If I'm getting the data, why would there be a warning? Most of the diagnoses of this error in these forum threads I've been reading keep mentioning bad queries or database connections. Apparently, neither of those things are the problem if I'm actually getting results. Enlightenment?
  17. Thanks, btherl! Gotta new tool in my arsenal!
  18. Hello all...again, forum helper, rab, was kind enough to provide me with some useful code: <?php $_REQUEST['contentID'] = (int)$_REQUEST['contentID'] < 0 ? 0 : (int)$_REQUEST['contentID']; if( $_REQUEST['contentID'] > 0 ) { $result = mysql_query("SELECT * FROM content WHERE contentID = '{$_REQUEST['contentID']}'"); if(!$result) { // ERROR } } else { // Need an ID } ?> Problem is...I'm not totally clear on what the first line is doing(please forgive the novice smell). In other words, I know what this part is doing... $_REQUEST['contentID'] = (int)$_REQUEST['contentID'] ...but not this part... < 0 ? 0 : (int)$_REQUEST['contentID'] I'm thinking it's some kind of short-form if/else statement, but... Enlightenment?
  19. Thanks, rab. By the way(stinking novice question to follow), the first part of this code I get... $_REQUEST['contentID'] = (int)$_REQUEST['contentID'] It's this part that tweaks my gray matter... < 0 ? 0 : (int)$_REQUEST['contentID']; I've seen this syntax before but never quite understood it's function. Is that a short-form of an if/else statement?
  20. Point well taken, cooldude832, about sticking raw data into a query...note to self. On the error, I should say that I'm getting all the desired results from this query. Essentially, the if statement is checking if the ID passed in a URL string exists as an ID for a row in the database. If it returns nothing, an error message displays. It all works fine, if tenuously, as the PHP error suggests. Let me ask, however, if doing this would be just as well... $result = mysql_query("SELECT * FROM content WHERE contentID = ".$_REQUEST['contentID']); if(!$result) { Or is it 6-or-one-half-dozen?
  21. The code for the query is: $result = mysql_query("SELECT * FROM content WHERE contentID = ".$_REQUEST['contentID']."");
  22. Hello all, In trying to clean up some PHP errors, I frequently get a "PHP Warning"(mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/ftp/path/to/file/content.php on line 30). Here's the code in question: $result = mysql_query('query here'); if(mysql_num_rows($result) == 0) { //this is the suspect line I'm pretty sure the fix is: $result = mysql_query('query here'); if(mysql_num_rows($result) == false) { //0 changed to false In reading PHP.net, http://us2.php.net/mysql_num_rows, it states for returned values "The number of rows in a result set on success, or FALSE on failure." Am I on the right track? I'm asking only because success with bug-checking using the error log tends to be spotty at best.
  23. Responding to revraz...I've always done that only because those ID's are just integers and not text strings. In looking at the other pages with errors, that does seem to be the common thread. PFMaBiSmAd, would revraz's observation about the end quotes in the query result in any of what you mentioned?
  24. There are various queries, but here's an example that keeps coming up... $result = mysql_query("SELECT * FROM calendars WHERE calendarID = ".$_REQUEST['calendarID']); while($row = mysql_fetch_array($result)) { //LOOP THROUGH DATA }
×
×
  • 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.