Jump to content

Novocaine88

Members
  • Posts

    18
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Novocaine88's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, I've not come accross the CONCAT function before, but this did the trick nicely. Again this is not a function i was aware of. Correct me if im wrong but a quick google and it seems that the data needed for that function (one field: YYYY-MM-DD) would not be in same format as the data i have in my database (two fields( Year: YYYY, Week: WW))
  2. Hi, i have a small problem with a query im trying to run. I have a table that has 'Year', 'Week' and some other irrelevant fields. The year number ranges from 2009 up until the current year The week number goes from 1 to 53 - I know 52 weeks in a year, but ive been told some years have 53 weeks, and subsequently my data has this, but again this is not necessarily important. So say I want to retrieve all the rows from week 40 in 2009 up until week 44 2011. My brain is having a hard time working this out, im sure its a lot simpler than im making it out to be in my head, but i just cant seem to get there. This is my current attempt at getting the result, even before i tested it i was pretty sure it would fail :-\ $StartYear = 2009; $StartWeek = 40; $EndYear = 2011; $EndWeek= 44; $ID= "a1"; $SQLCommand = sprintf("SELECT * FROM WeekYear WHERE ( (Year >= '%d' AND Week >= '%d') AND (Year <= '%d' AND Week <='%d') ) AND ID = '%s' ORDER BY Year, Week", $StartYear, $StartWeek, $EndYear, $EndWeek, $ID); This obviously doesn't work because the query is only looking for week numbers between 40 - 44, rather than week 40 - 52/3 in 2009, week 1-52/3 in 2010 and week 1-44 in 2011. Can anyone help me out here, i've been staring at this for too long and nothing is coming to me. Cheers
  3. Ah yeah i noticed this mistake myself shortly after posting. This part worked a treat, thanks. As you can probably tell im not all that great with arrays, i forgot this was how to go about printing them. Cheers
  4. EDIT: I have just changed one small bit: if(isset($_COOKIE['history'])) to if(!isset($_COOKIE['history'])) which was just a sily mistake on my part. It does now show 5 rows (once i've visited 5 pages). I am still however having problems actually getting that data, its still coming up blank
  5. Hi, I'm trying to store the last 5 pages a user visited on my website and i can't seem to get it working. I've found a couple of pages that kind of tell me what i thought i need, but they dont seem to be correct. Anyways heres what i've tried; if(isset($_COOKIE['history'])) { // if theres no cookie set yet, then set it with the current page. // first we create an array $HistoryArray = array($_SERVER['PHP_SELF']); // next we set the cookie with serialized() array setcookie("history", serialize($HistoryArray), time()+(60*60*24*31), "/"); } else { // if we already have a cookie set we want to get the data from it, add that to an array and reset the cookie // first we unserialize() the cookies data $HistoryArray = unserialize($_COOKIE['history']); // next we add to the array $HistoryArray[] = array($_SERVER['PHP_SELF']); if(count($HistoryArray) > 5) { // if theres more than 5 rows in the array then we want to remove the first row array_shift($HistoryArray); // finally we set the new cookie with the updated page } setcookie("history", serialize($HistoryArray), time()+(60*60*24*31), "/"); } I have this in an include thats present in every page in my site And then a test page i've made to try and see if this actually worked looks like this; $NumCookies = count(unserialize($_COOKIE['history'])); echo "Num Cookies: ".$NumCookies."<br />"; for($i = 1; $i < $NumCookies + 1; $i++) { echo "Cookie number ".$i." : ".unserialize($_COOKIE['history'][$i])."<br />"; } To me this logically seems to make sense right? I only ever get one row listed no matter how many pages i go to on my website. I also tried something similar to this with a manually created array just so i could test if my test page was even working. This almost worked, using the same code as above it counts the number of elements in the array correctly and loops through it but the value of the cookie is always blank. What am i doing wrong, anyone know? cheers
  6. Firstly you would want to get your post value if the form has been submitted. if($_POST) { $defpt = $_REQUEST['defpt']; } Then use a function like so; function SelectIt($Value1, $Value2) { global $Select; if($Value1 == $Value2) { $ReturnValue = "selected=\"selected\""; $Select = "Selected"; } else { $ReturnValue = ""; } return($ReturnValue); } you would then construct your select tag like so <select name="defpt"> <option value=".9" <?php echo SelectIt(.9 , $defpt) ?>>attacker</option> <option value=".9" <?php echo SelectIt(.9 , $defpt) ?>>Economist</option> // this line would need to have a different value to the one above <option value="1.15" <?php echo SelectIt(1.15 , $defpt) ?>>Miner</option> <option value="1.5" <?php echo SelectIt(1.5 , $defpt) ?>>Explorer</option> <option value="1" <?php echo SelectIt(1 , $defpt) ?>>Standard</option> <option value="1.1" <?php echo SelectIt(1.1 , $defpt) ?>>Researcher</option> </select> having the same value for more than one option will cause this to not work properly. If you need some options with the same value it might be better to make the values of the option unique, but handle what those unique values equal post form. e.g. if($defpt == "attacker") { $value = 0.9; } if($defpt == "Economist") { $value = 0.9; } if($defpt == "Miner") { $value = 1.15; } // etc...
  7. Hi, I'm very new to trying to use facebook's api/sdk and i'm struggling to say the least. I'm trying to put in place code that will simply allow me to show some extra content on a web page if a user has "liked" it. I'm not talking about a page on facebook. This is a separate website that currently has a like button using xfbml using this code; <script type="text/javascript"> window.fbAsyncInit = function() { FB.init({appId: '#####', status: true, cookie: true, xfbml: true}); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script> <fb:like-box profile_id="######" width="220" stream="false" header="false" connections="0"></fb:like-box> Ideally i'd like to be able to place something as simple as the following code anywhere on a page; if($HasLiked) { // show some extra content } Every example i come across is considering my website an "app" and tells me that the user needs to authenticate my website to access the users information, which just isn't what i want. I need only to check whether the user has liked the website they are on, nothing else. If the facebook button itself can do this, surely it can't be that hard for me to do as well? Anyway, some guidance on this would be great. Cheers
  8. Thanks for the reply, however I'm not sure how you mean me to use that? the url as it is, mydomain.com/location/foo-bar/ the get value of that will still be foo-bar after using rawurlencode(). I basically need a way to replace a single hyphen with a space, and if there are 2 hyphens in a row replace them with a single instance. I would of thought regex would be the best option for this but like i said, i've little experience with them. Although I said I don't want to change the character that represent a space in teh browser url, if its easier and underscore might be acceptable. e.g. "foo_bar" to represent 2 separate words whilst "foo-bar" would represent one after getting it from the url.
  9. Hi, I've got a little problem at the moment with how to replace varying amounts of hyphens in a browser url. scenario: I have a borwser url mydomain.com/location/foo-bar/ where "foo-bar" is actually "foo bar" in the database (no hyphen). I also have urls where the entry in the database does have the hyphens e.g. "foo-bar" Now im not quite sure how to go about writing these urls, and how to manipulate the GET values from them. what I've tried My first thought was to add a secondary hyphen to the url so that the database entires that equal "foo-bar" would be "foo--bar" in the browser url and the entries in the database that equal "foo bar" would have the single hyphen "foo-bar". Then i would use preg_replace to deal with the single hyphens by removing them and replacing with a space, and after that finding the double hyphens and replacing them with only one. In theory this should work (I think), but I've only recently got into using regex, this is what I've tried; $CNE = preg_replace("/[-]{1}/", " ", $CNE); $CNE = preg_replace("/[-]{2}/", "-", $CNE); so I've tired to match the single hyphen and then the double, but even before I tested this I didn't think it was going to work with this code. Can anyone correct me, or maybe suggest a better way to go about this issue. (note: using a different character to replace spaces is NOT an option in this case) Thanks
  10. I've given this a whirl and it seems to do the job very nicely. Cheers
  11. Yeh sorry, that is what i have used. Didnt check what i wrote Thanks for this, ill give it a go. It sounds like a better solution
  12. Right, I've got what i wanted. Thanks for all your suggestions. What I did was use the UPDATE table SET rand_order = RAND() and the SELECT * FROM table ORDER BY band, RAND() (thanks btherl) which did exactly what i wanted. Randomized the results completely, then when printing them out ordered them initially by their band and then their random number. And I've been told I can set up a cron job to run the randomization script once a week to changg the order again. (not sure if this is sort of what you meant spiderwell) Once again, Cheers for the help
  13. <input type="hidden" value="" /> And of course you can enter something into the value so you can get it later with php
  14. So would SELECT * FROM table ORDER BY band, RAND() randomize the order of the results within their separate bands? If thats the case, then that sounds good. But how would i go about doing this automatically only once a week? It looks like your suggesting a manual once a week "re-order"
  15. Hi, I'm not necessarily looking for code examples for my problem, (they are welcome but its not my explicit goal). I'm looking more for advice on how to go about tackling the problem i have. what i already have Currently i have a search getting results from a MySQL database. The results are ordered by one field that signifies their importance. Many of these results have the same value in this one column, and i have a switch statement to distinguish different content/styles for the different values. (there are just over 10 different bands) So the most important results are shown first and with a different style to the ones below it. (some bands have the same styling) what i need I would like to be able to randomize the results but only randomize the results within their specified bands. e.g. lets say theres 100 results in band A and 100 in band B. I still want everything in band A to be listed above band B, but i would like to randomly change the order of the results in band A and band B, (in this case once a week). I need to save the order of this randomization (client/server side?) for a week, then run the script again to set a new order. Now I would still class myself as an amateur php'er so at this stage i dont even know how i would go about separating the bands and randomizing their results independantly, let alone causing this functionality to run only once a week. So can anyone suggest a way i might go about this? I'm pretty stuck right now. Cheers
×
×
  • 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.