Jump to content

UrbanDweller

Members
  • Posts

    123
  • Joined

  • Last visited

Everything posted by UrbanDweller

  1. Hey, I have this code below which seems to completely fail sending my laptop cpu fan on a frenzy. All I am wanting to do is find whether the id in the url is located inside the array below else state its not in an error saying its not a valid id (for people who change the url shown below). At the moment it doesnt like the else statement if the isset clause it not true. (I have also tried, array_key_exists) All I can think is that it get stuck looking for an id that doesnt exist inside the array but keeps searching though I dont know much about arrays etc. Besides this when a id is inside the array the script works like I want it to. Any ideas would be much appreciated as this is hold me back at the moment //url: http://localhost/website/shop.php?id=10197 // Array is built from table prior to this as it will grow in size $_SESSION['storesProducts'] = Array ( [10197] => 0 [10198] => 0 [10199] => 1 [10200] => 1 [10201] => 1 [10202] => 1 [10205] => 0 [10206] => 1 [10207] => 1 ) if(isset($_SESSION['storesProducts'][$id])){ $storesProducts = $_SESSION['storesProducts'][$id]; if($storesProducts == 0){ $list = $this->displayCategories($id); }else{ $createProducts = new constructProducts(); $products = $createProducts->pagination($id); } }else{ $list = "ITS NOT HERE"; } $output = new outputShop(); $output->display($list, $products);
  2. Hey, In my script I am currenlty working on I have 2 classes one which calls the second in the hope it will return a value to it but doesnt send the variable back. The example code below give you and idea of what I am looking for as my script it too long to add. class oneClass{ function bar(){ $var1 = "test" $two = twoClass(); $result = $two->foo($var1); echo $result; } } class twoClass{ function foo($var1){ $result = $var1 . ' is successful!'; $this->fooTwo($result); } function fooTwo($result){ $result = $result . ' Pass me back now?'; return($result); //Want to pass the variable back to "oneClass->bar();" } } // Starts script $testme = new oneClass(); $testme->bar(); This is a very simple example but states what i am wanting to. Any ideas would be much appreciated! Thanks
  3. I decided to re-look over my code and have completely reworked it into a cleaner look without having to back in to previous classes. Thanks for comment
  4. Yeah it is but how I started coding this, I may have to reconsider moving some functions out of class a into class b instead as the variable pass through will get messier than i want it.
  5. Ive always had a bit of trouble with php and effectively talking between classes, as the example below shows I want to call a first class->function that will later call a different class and its function then call the previous class again. I havent been able to find any examples that state how to do this if possible. <?php class A{ function b(){ //does required code etc... $B = new B(); $B->BA(): } function AB(){ echo "I WANT TO END UP HERE, from class B function BA"; } } class B{ function BA(){ //does required code etc... // //Unsure how to call class/function A->AB } } $a = new A(); $a->AB(); ?> Is this possible as it helps separate my code in to nice and easy to read Thanks
  6. Thanks for the input the main issue was retrieving the previous category name which I had to use the database as I found was the best/easiset solution for my dynamic page as the admin could add more and more categories. So i worked back from the current page via the category parent id all the way to home page which seems to have worked perfectly. I dropped the refeerer idea to as its too risky to create crumb urls
  7. Sorry for double post but, is $_SERVER["HTTP_REFERER"} safe to use to get previous page link for my crumbs as ive heard a lot about it being untrustworthy or is that just external urls?
  8. Yeah i have always thought about caching but my knowledge isnt ready to start diving into new areas like that yet as my customer base isnt large enough nor is my coding skills.
  9. Hey, I'm currently planning on how i will code some breadcrumbs for a shopping site where the admin can add more options/levels to the database which in turn store products. I understand how to get the url of the previous options/level but am stuck on retrieving the name of the level and can only imagine retrieving it from the database. Though Its possible to do so is there any other method as relying on the database for crumbs seems like a easy way out or am i just picky? the typical url is like so: website.com/shop.php?cat_id=1004, so i cant retrieve the name from it unless i cross reference it to its database name and dont know how to retreive from their <a href> tag. On a side note is there a graph that can show a general outline of how many db queries a server can make per second etc depending on its hardware? Thanks.
  10. Hey all, Im currently working on a site which I save a cookie on users computer for 1 month as well a row in a table with the 1 month expiring date plus cookie id. What I would like to know is if theres a way to make the server check the table every day at say 12pm to see if any corresponding user cookies in each row have expired on that day as to remove them from the table to match the expiring cookie on the users computer? I would like not to have to rely on a user/admin accessing in to make a script run instead have something thats timed to go off automatically instead? Is there anyway of doing this? Thanks!
  11. Hey, I have just started using cookies and have got the basic idea of creating and accessing the simple cookies but now I am wanting to be able to check if a cookie already exists on the users computer before overwriting the current one. <?php if(!isset($_COOKIE['testCookie'])){ setcookie("TestCookie", "username", time() + (24 * 60) ) } ?> <html>....</html> At the moment my page just doesn't get past this piece of code any ideas? Cheers
  12. Well i found a good example on global variable which seems tidy and is working too.
  13. There's one function before the function where the variable is created so that code doesn't work just pulls up undefined variable. The variable will be returned from a different function that been called first. external script (defaultList is called then getCategoryList returns the variable): function defaultList(){ $sortBy = "opt_1"; $order = "DESC"; $result = dbQuery("SELECT opt_1, opt_2 FROM test_tbl ORDER BY $sortBy $order"); getCategoryList($result); function getCategoryList($result){ //MYSQL code happens and needed stuff is turned into the variable list return $list; } }
  14. Hey, I am currently trying to get a variable created inside a require_once script to be echoed inside the main page that called the require. The script below is a basic idea of what i want to do. I just want to be able to create a basic variable none of this session stuff as its makes life harder at the moment. Thank guys, hope the snippet below gives you a better idea. Main Code: <body> <?php require_once("makesVariable.php"); <div> // Variable I want to be echo "NOT WORKING" echo $var; </div> ?> </body> External PHP Code: <?php //Function gets called by previous code to create the needed variable function createTheVariable(){ $var = "I am the variable to be called"; return $var; } ?>
  15. Ajax seemed like the easier way to do this as making a variable 4 arrays deep seems a bit to intricate to especially when the database could get bigger. This way I only have 1 column to search but will require multiple queries. This will only be used as a admin feature to add categories/products so single user access.
  16. Figured it out in the end was trying something a bit different to that guy but cheers.
  17. Hey all, I have finally worked out ajax in jquery since i have only worked with jquery for the past couple of days. Currently i have 4 drop down boxes that populate the one after the next depending on the amount of tables rows the ajax returned, this normally is about 2-6 out of a possible 20-30 in the table. Im sending two mysql queries on select click event. My question is a I have only does local testing so I don't know the response speed to these ajax calls and was wondering if you think there will be much delay from the time sent to the time its recieved and displayed? Thanks
  18. Sorry but i dont understand how exactly how jquery ajax call is able to retreive the variable created in the php function that was called At the moment all im trying is to return a php string to jquery to use all i can imagine is success: function(phpVar){ }); ?
  19. Surely it will slow ur site down reqesting so many queries a second
  20. Hey, I have never touched AJAX due to never needing it until now. I have looked up some tutorial but dont understand how they link to what you need done. What I am wanting to do is send the select option value to a php function that then searches the table for the required output then it in another select tag depending on what option is chosen. I basicly need help defining the need ajax syntax to do such a process? by the way does php create the select tags or javascript? <select id="elem1"> <option value="101">category one</option> <option value="102">category two</option> <option value="103">category three</option> </select> <?php function getChild(){ $parent_id = $_GET['elem1]; $result = dbQuery("SELECT cat_id, cat_name FROM catagory_tbl WHERE parent_id=$cat_id"); }
  21. Why not use arrays so stack up data then insert into db?
  22. Hey, I have always wondered if there is a correct way of displaying variables inside html. Typically I would echo each variable inside php tags when displaying outside of a loop but what would you recommend for a while loop while more than say 5 variables to display? echo "<tr><td>".$var1."</td></tr>"; OR <tr><td><?php echo $var1; ?></td></tr>
×
×
  • 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.