Jump to content

GingerRobot

Staff Alumni
  • Posts

    4,082
  • Joined

  • Last visited

Everything posted by GingerRobot

  1. Or your eyes went 5 centimetres to the right and you seen the creator name I was waiting for that smart comment. Shame it took you over a week really. I actually saw the topic title in the 'last post' section on the index page. It only shows who posted last, which(at the time) wasn't you.
  2. Hmm, ive just realise i need to re-think this anyway. My method(even if it worked!) would run into problems with negative numbers.
  3. Well, if you simply wanted to check both fields for the search term, then it would just be a case of modifying your query: $query = "SELECT * FROM products WHERE name like '%$searchTitle%' or type like '%$searchTitle%'"; However, you may want an option for the user to select which fields to search in. In which case, you will need to pass an additional value through the url, which is the field to search. Also, dont forget that you'll be needing to protect yourself from any malicious users - you'll need to validate the user input.
  4. Well, the manual is your best friend for functions. floor() rounds a number down. The 86400 is the number of seconds in a day. Since we have a time difference in seconds, we divide by the number of seconds in a day to get the number of days difference. We round down so we show a whole number of days. That is exactly the problem. Id personally leave it as a number of days.
  5. Do you think you could come back when you have a keyboard capable of conveying your problem to us? Seriously, i've absolutely no idea what the problem is, and half of the trouble is that i can barely read what you've written!
  6. So you've stored a timestamp in the database for when they signed up? You'll be wanting to do something like: <?php $todays_date=time(); $date_joined=$member_row['user_joined']; $diff = $todays_date - $date_joined; $days = floor($diff/86400); echo 'You joined '.$days.' days ago'; ?> If its a date you've stored, you'll need to convert it to a unix timestamp with the strtotime() function.
  7. Im trying to make a graphical calculator at the moment (yeah, i know it was 1st competition - didn't have the time or knowledge then) - and im currently working on a function to parse the equation. Im struggling a little with indices. Im trying to transform x^y into pow(x,y). What i have so far: <?php $eq = "6+4564.2151^145.63-3"; $eq = preg_replace("/(\+|\-|\*|\/)+(.*)\^(.*)(\+|\-|\*|\/)+/",'$1pow($2,$3)$4',$eq); echo $eq.'<br />'; $eq = "4564.2151^145.63"; $eq = preg_replace("/(\+|\-|\*|\/)+(.*)\^(.*)(\+|\-|\*|\/)+/",'$1pow($2,$3)$4',$eq); echo $eq.'<br />'; ?> Which produces output: 6+pow(4564.2151,145.63)-3 4564.2151^145.63 So, as you can see, the pattern works ok assuming that there are operators either side of the power expression, but if the only thing within the string is a power, then it doesn't work. I thought that by using the * quantifier(which is 0 or more as i understand) rather than the + quantifier, this would solve my problems: <?php $eq = "6+4564.2151^145.63-3"; $eq = preg_replace("/(\+|\-|\*|\/)*(.*)\^(.*)(\+|\-|\*|\/)*/",'$1pow($2,$3)$4',$eq); echo $eq.'<br />'; $eq = "4564.2151^145.63"; $eq = preg_replace("/(\+|\-|\*|\/)*(.*)\^(.*)(\+|\-|\*|\/)*/",'$1pow($2,$3)$4',$eq); echo $eq.'<br />'; ?> This gives: pow(6+4564.2151,145.63-3) pow(4564.2151,145.63) So, this works when there are no operators, but not when there are operators. I hope i've explained properly. Any help would be much appreciated. Ben
  8. Oh, i just noticed, you've called your constructor '_construct' its '__construct' - a double underscore.
  9. Quite possibly. Are you using php5? Before php5 the constuctor function had the same name as the class, rather than being called __construct.
  10. Well, how exactly do you say AJAX? Do you pronouce it as in the dutch football team - "i-yax" or, as it first appears, "a-jax" ? After a bit of googling, i suspect the later. Largely because no-one appears to have heard of the dutch team!
  11. Unless i missunderstood, dont you need to check that status is not 2 if its the user is who the message was to, and check status2 if the message was from the user? I think this might be what you are after: SELECT * FROM `mail` WHERE ((`u_to` = $userid AND `status`!=2) OR (`u_from` = $userid AND `status2` != 2)) AND `parentid` = 0 ORDER BY `date_sent` DESC
  12. I hope it does help. I do agree that it is hard to find good tutorials and examples of using OOP. I find that things get over-simplified for the sake of example, and end up becoming pointless.
  13. Until recently, i'd hardly used OOP at all. At the moment, im trying to make a graphical calculator(it was the 1st competition, but i didn't have the time, or really the knowledge, to do it back then). I decided to attempt this in an OO manner. Perhaps the way i have structured my code would help you: <?php class graph(){ //list all the attributes of the class - sizes and scales for x and y, the image handler etc function __construct($data){//i pass in an array of data to set up the image //the constructor creates the image and ouputs the correct header. It sets the attributes //of the class from the data passed to it } function colours($colour){ //takes a colour in a string and passes back a colour identifier } function drawaxis(){ //this function drax axis on the graph } function plot_equation(){ //plots the equation we are drawing } function parse_equation{ //parses a string as an equation to make it useable - this is the bit im working on now } function __destruct(){ //outputs the image } } ?> The idea behind my usage of constructors and destuctors is that i have put everything that needs to be set up before the class can be used in the contructor - you cant draw the axis/plot an equation until you've created an image etc. The destructor is used to output the image after the last call to the class.
  14. Oh dear. It's almost as bad as the London 2012 logo. Now THAT is shocking. At least the conservatives only paid £40,000 for theirs, the olympic logo cost 10x that! http://news.bbc.co.uk/sport1/hi/other_sports/olympics_2012/6718243.stm
  15. With that attitude, i dont suppose people will be inclined to help you with it. However, ill give the french a shot if i get time at some point - should probably not go all summer without doing any french
  16. Well, do you have a syntax error or not? If you have a syntax error, you'd be getting an error message, with a line that the error occurs on. I assume the problems lie with the lack of quotes around your strings in your update queries. Also, you don't need to update each field in a separate query. Finally, whenever you have a problem with queries not working, add an or die statement to the query. Try: <?php $sql = "UPDATE $table SET quoteid='".$_POST['quoteid']."', name='".$_POST['name']."', brand='".$_POST['brand']."', address='".$_POST['address']."', city='".$_POST['city']."', state='".$_POST['state']."', zip='".$_POST['zip']."', latitude='".$_POST['latitude']."', longitude='".$_POST['longitude']."', zoom='".$_POST['zoom']."'," mysql_query($sql) or die(mysql_error().'Query:'.$sql); ?>
  17. Well, to be able to select the most popular, you're obviously going to have to store the number of views. So, lets say your add a field `views` to your database: $sql = "SELECT * FROM `news` ORDER BY `views` DESC LIMIT 5"; As for your second solution, this is far more complex. Im not entirely sure of the best method. However, i would assume it would envolve storing some keywords for each article. I think you'll then be needing to do a full-text search to be able to produce results based on relevance. Take a look at this tutorial on full-text searches: http://www.phpfreaks.com/tutorials/129/0.php There might be a better method, however.
  18. Im a little confused as to what you are trying to do. If i run this code, i get: Response:200 For http://www.google.com Response:200 For http://www.google.com/intl/en/options/ Response:200 For http://www.google.com/intl/en/ads/ Response:200 For http://www.google.com/services/ Response:200 For http://www.google.com/intl/en/about.html -------------------------------------------------------------------------------- http://www.google.com/intl/en/options/ http://www.google.com/intl/en/ads/ http://www.google.com/services/ http://www.google.com/intl/en/about.html Do you mean to say you want to retrieve all of the links from http://www.google.com/intl/en/options/ , http://www.google.com/intl/en/ads/, etc (and presumably any links found on each of those pages?) ?
  19. As far as im aware, option 2 & 3 are the same. The only differant behaviour with option one is that it allows you to not always pass by reference. Wether or not there would be a time that having a function which sometimes passes by reference and sometimes by value would be useful/required, im not sure.
  20. Thorpe: The id is defined with this line: $forumid = $_GET['forumid']; loony383 : However, in your second script, you don't appear to define $forumid anywhere.
  21. Sure, use the NOT IN operator: SELECT * FROM `user` WHERE `userid` NOT IN (23,24,46)
  22. Could be way off - ive never used SOAP, but could the $_SERVER['SERVER_PROTOCOL']; variable be what you are looking for?
  23. I understand where you are coming form neylitalo, but given the nature of the internet, im not convinced the problem of monopolies exists as much as it does in other industries. Given the sheer number of websites, i think there will always be alternatives. As for worrying about walmart joining with google...you should only get worried if google were to join with microsoft I would argue that given the way google is heading with their office applications online, they are quite possibly best placed to halt the microsoft domination: if the technology is good enough, people will start to wonder what the point of paying for office is if you can just use google's applications on the internet for free. Sure, open office exists for linux - but given the existing popularity of google; and the relatively obscurity of linux to joe blogs in the street, google can seriously rival microsoft. Thats my opinion anyway.
  24. I assume that by "did not work" you meant you receieve an error? The eval() function expects php code. If you start the string you are evaluating with HTML, you'll get an error. You need to close php first. Try something like: <?php $content = "<html><head></head><body><?php echo 'hello world!';?></body></html>"; $content = eval('?>'.$content); ?>
  25. Well this is completely a javascript issue, but, i've no idea what the problem is. Your javascript code is fine. I can only assum its to do with the way you call it. Try: <html> <head> <script type="text/javascript"> function check() { if(document.flight_ticket.yn.checked == false) { alert ("Please check YES or NO to confirm flight"); return false; }else{ return true; } } </script> </head> <body> <form name="flight_ticket" onSubmit="return check()"> <input type="checkbox" name="yn" /><br /> <input type="submit" name="submit" /> </form> </body> </html> EDIT: Good point. I was assuming the idea was to see if the checkbox had been clicked, even if the error message is somewhat strange.
×
×
  • 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.