Jump to content

Philip

Staff Alumni
  • Posts

    4,665
  • Joined

  • Last visited

  • Days Won

    20

Everything posted by Philip

  1. Take a look at natsort() It'll sort numbers by what you think is correct, 1,3,5,20,41 instead of 1,20,3,41,5
  2. Change: $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice"); to: $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice") or die(mysql_error());
  3. read my edit, and update the code to that
  4. Because on the end of $area you have ORDER BY, instead of in your query. If you change your original script to this: $type=($_POST['type']=="") ? "" : "AND type = '{$_POST['type']}'"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "AND maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "AND area = '{$_POST['area']} "; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM properties WHERE bedrooms >= '$bedrooms' $type $maxprice $area ORDER BY maxprice"); Does it fix it? By the way, you still need to fix the way it is setup with regards to the AND's. I might have maxprice, but not area, and it'll show: "maxprice < 500000 AND ORDER BY maxprice" which is incorrect syntax. EDIT: fixed the AND problem, moving the and's to the font of the variables will allow it to work properly.
  5. Well, there are a few things wrong with that query. first of all, it's always a bad idea to have direct user input into a database. $type=($_POST['type']=="") ? "" : "type = '{$_POST['type']}' AND"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "area = '{$_POST['area']}' ORDER BY"; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM properties WHERE $type bedrooms >= '$bedrooms' AND $maxprice $area maxprice"); Change that to: $type=($_POST['type']=="") ? "" : "type = '{$_POST['type']}' AND"; $bedrooms=$_POST['bedrooms']; $maxprice=($_POST['maxprice']=="") ? "" : "maxprice < '{$_POST['maxprice']}' AND"; $area=($_POST['area']=="") ? "" : "area = '{$_POST['area']}' ORDER BY"; //connect to mysql //change user and password to your mySQL name and password mysql_connect("*****","*****","*****"); //select which database you want to edit mysql_select_db("****"); //POST the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $Query = "SELECT * FROM properties WHERE $type bedrooms >= '$bedrooms' AND $maxprice $area maxprice"; echo $Query; $result = mysql_query($Query) or die(mysql_error()); Maybe then you'll see the problem - especially when maxprice isn't empty, but area is.... You'd get something like "maxprice < 500000 AND maxprice"
  6. Read the error, it tells you what is wrong - You did not supply any parameters in the setcookie() function call.
  7. I don't know why you created a new topic when you had this one Just the same as a while, <?php $i = 1; foreach($array as $key=>$value){ $i++ //echo table if($i == 5){ //echo banner $i = 1; } }
  8. <?php function random_float ($min,$max) { return ($min+lcg_value()*(abs($max-$min))); } echo round(random_float(1,7),2); ?> There is probably a better way, but that's just one way
  9. It passes the variables/strings as parameters instead of by concatenation into one string. I also changed the type of quotes - personally I think it's easier to read it that way (just my opinion)
  10. As taken from a php.net comment: <?php function random_float ($min,$max) { return ($min+lcg_value()*(abs($max-$min))); } echo random_float(1,7); ?> You could then take it to whatever decimal you wanted.
  11. My preferred way when coding: echo '<div id="',$row['arena'],'">'; Tweak on samshel's (the 1st escaping slash was in wrong spot): echo "<div id= \"".$row['arena']."\">"; And premiso's should take care of you too echo "<div id=\"{$row['arena']}\">";
  12. As angel said, add or die... I'm going to take a guess and say it's because you don't have single quotes around your values. $str = "SELECT * FROM `actionlog` WHERE `itemid` = '$match[2]' && `action` = '$v[3]'"; echo $str; // does this look correct, and does it run in something like PhpMyAdmin? $qry = mysql_query($str) or die(mysql_error()); $num = mysql_num_rows($qry); if($num <1 ) // rest of script....
  13. <?php $var = (int) (14/3); echo $var; ?> Will echo 4
  14. Or, similarly: <?php $i=1; while($row = mysql_fetch_array($result)) { if(!($i%5)) echo '*banner '; echo $i,' result<br />'; ++$i; } ?>
  15. Look into SMF's ssi.php
  16. That's bad practice. It will throw a notice about that, because it's trying to look for a defined constant. Example: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); define('hi', 'hello there!'); $a = array('a'=>'b', 'hi'=>'hello'); echo $a[hi]; // wrong! ?> and... <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $a = array('a'=>'b', 'hi'=>'hello'); echo $a[hi]; // wrong! ?> Where, when correctly coded: <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $a = array('a'=>'b', 'hi'=>'hello'); echo $a['hi']; // correct! ?> @OP: Unfortunately, I don't think there is any other way.
  17. <td color = 'white' width='50%'> to: <td style="color:'white'; width:'50%';">
  18. It suppresses any errors, so you wouldn't see something like: Warning: Blah blah blah is blah in file.php (line 3)
  19. function count ( $query ) { $q = mysql_query ( $query ) or die(mysql_error()); return mysql_num_rows ( $q ); } I would imagine it's because you cant connect to the db. But lets see what it dies. Oh and as mentioned, be careful using the same function names.
  20. varName = "<input type=\"button\" onClick=\"alert('hello');\">"
  21. Although I've never done this, I can only offer a generalization. When users just close their browsers, the server/website will still think the user is online. There is no way to log off the user when they close the browser. So the only thing you can fall back on is sessions. Since sessions live on the server for 20 minutes (I think that's the default) You'd have to check if there has been any activity for that user during that time period. And if they have not made any post or logged onto any forum, you can then probably set their account as offline.. As for the sessions, you can change that too if you don't like the default... Sessions default is 2 hours i believe. Best way to do this (as listed above), and how most forums do this... Every time they visit a page, it updates their last timestamp (and location sometimes). Then when listing, whoever's timestamp is greater than now - X minutes, display.
  22. Well, what's before: //project e-mailer////////////////////////////////////////////////
  23. Why not in your query use AS SELECT Detail.id as dID, Detail.up_test, Detail.count_test, Detail.name, Detail.server, Detail.port, Detail.result, server.id as sID, server.ip, server.name FROM `Detail`, `server` WHERE Detail.server = sID; later on call it as: $row['dID'] or $row['sID'] edit: just read the other post about trying to not use as. Unless you did it via the numeric index (fetch_array) then no.
  24. Well, $maxposts is empty. Thus it's giving LIMIT 0, edit: beat me to it
  25. a few things, but this should work: $v = "yes"; if(empty($v)) { if (preg_match_all("m/$v/i", $values{$k})) $out .= "checked"; } Where is out being set? You should be careful with trying to continue a variable that may not exist
×
×
  • 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.