Philip
Staff Alumni-
Posts
4,665 -
Joined
-
Last visited
-
Days Won
20
Everything posted by Philip
-
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
-
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());
-
read my edit, and update the code to that
-
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.
-
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"
-
Read the error, it tells you what is wrong - You did not supply any parameters in the setcookie() function call.
-
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; } }
-
<?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
-
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)
-
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.
-
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']}\">";
-
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....
-
<?php $var = (int) (14/3); echo $var; ?> Will echo 4
-
[SOLVED] while($row = mysql_fetch_array($result))
Philip replied to johnwayne77's topic in PHP Coding Help
Or, similarly: <?php $i=1; while($row = mysql_fetch_array($result)) { if(!($i%5)) echo '*banner '; echo $i,' result<br />'; ++$i; } ?> -
Look into SMF's ssi.php
-
basic php/mysql syntax question on a single line of code
Philip replied to cunoodle2's topic in PHP Coding Help
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. -
<td color = 'white' width='50%'> to: <td style="color:'white'; width:'50%';">
-
It suppresses any errors, so you wouldn't see something like: Warning: Blah blah blah is blah in file.php (line 3)
-
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.
-
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.
-
Well, what's before: //project e-mailer////////////////////////////////////////////////
-
basic php/mysql syntax question on a single line of code
Philip replied to cunoodle2's topic in PHP Coding Help
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. -
[SOLVED] You have an error in your SQL syntax
Philip replied to almightyegg's topic in PHP Coding Help
Well, $maxposts is empty. Thus it's giving LIMIT 0, edit: beat me to it -
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