| Recommend this page to a friend! |
| DrasticTools | > | All threads | > | WHERE queries | > | (Un) Subscribe thread alerts |
| |||||||||||||||
I have no hair left, so I thought I should now ask...
if ($HTTP_POST_VARS['FieldName'] == "" || $HTTP_POST_VARS['Like'] == '') { class mysrc extends drasticsrcmysql { protected function select(){ $res = mysql_query("SELECT * FROM $this->table" . this->orderbystr, $this->conn) or die(mysql_error()); return ($res); } } } if ($HTTP_POST_VARS['FieldName'] != "" && $HTTP_POST_VARS['Like'] != '') { class mysrc extends drasticsrcmysql { protected function select(){ $res = mysql_query("SELECT * FROM $this->table WHERE `$FieldName` LIKE '%$Like%'" . $this->orderbystr, $this->conn) or die(mysql_error()); return ($res); } } } I can not get variables to be recognised inside the protected function, from $POST statements ! I have tried escaping with single quotes, double quotes, escaped single and double quotes... I want to pass a FieldName and Like query string, to the page... Im, old, bald ( now ), and looking for clues. Any suggestions appreciated. Thanks all Rick
Sorry, let me add...
The error message: Unknown column '' in 'where clause' Cheers Rick
I'm guessing that register globals is off (like they should be).
Is there any particular reason you aren't passing the variables to your class? $blah=new mysrc(); $blah->select(trim($_POST['FieldName']),trim($_POST['Like'])); class mysrc extends drasticsrcmysql { protected function select($FieldName,$Like){ if ($FieldName==''||Like=='') { $res = mysql_query("SELECT * FROM $this->table" . this->orderbystr, $this->conn) or die(mysql_error()); } if ($FieldName!=''&&$Like!='') { $res = mysql_query("SELECT * FROM $this->table WHERE `$FieldName` LIKE '%$Like%'" . $this->orderbystr, $this->conn) or die(mysql_error()); } return ($res); }
Joseph,
I thank you for your input... You said: "Is there any particular reason you aren't passing the variables to your class?" If I can't plead the 5th amendmant, I'll choose ignorance. Joseph, As you can see, I'm no coder, just an old coot trying to hack away at a database... I love the idea of inline editing, so DrasticGrid and I need to get along. With your help, this is now what I have. I am using DrasticTools6011 My class file dt_drasticSrcMySQL.class.php is unchanged. I now have the following in the top of my php file: <?php define("PATHDRASTICTOOLS", ""); include(PATHDRASTICTOOLS."dt_mysqlconfig.php"); include(PATHDRASTICTOOLS."dt_drasticSrcMySQL.class.php"); $blah=new mysrc(); $blah->select(trim($_POST['FieldName']),trim($_POST['Like'])); class mysrc extends drasticsrcmysql { protected function select($FieldName,$Like){ if ( $FieldName == '' || $Like == '' ) { $res = mysql_query("SELECT * FROM $this->table" . $this->orderbystr, $this->conn) or die(mysql_error()); } if ( $FieldName != '' && $Like != '' ) { $res = mysql_query("SELECT * FROM $this->table WHERE `$FieldName` LIKE '%$Like%'" . $this->orderbystr, $this->conn) or die(mysql_error()); } return ($res); } } $src = new mysrc($server, $user, $pw, $db, $table, $options); ?> I do not see where or how to use the $blah, Im guessing Im still missing somthing as my error is now: Fatal error: Class 'mysrc' not found in /mypath/www/mydb/includes/dt_drasticSrcMySQL_Products.php on line 6 Line 6 is: $blah=new mysrc(); No doubt, you knew that already... Your support is appreciated, Thankyou Rick
np. i just stumbled across your question and thought i'd pitch my input in.
the error is totally my fault. I gave a bad example by definine the object before the class. let me go a bit further. I was using $blah for the purpose of example but what you're wanting to use is $src (from looking at your example). so what you gave becomes <?php define("PATHDRASTICTOOLS", ""); include(PATHDRASTICTOOLS."dt_mysqlconfig.php"); include(PATHDRASTICTOOLS."dt_drasticSrcMySQL.class.php"); class mysrc extends drasticsrcmysql { protected function select($FieldName,$Like){ if ( $FieldName == '' || $Like == '' ) { $res = mysql_query("SELECT * FROM $this->table" . $this->orderbystr, $this->conn) or die(mysql_error()); } if ( $FieldName != '' && $Like != '' ) { $res = mysql_query("SELECT * FROM $this->table WHERE `$FieldName` LIKE '%$Like%'" . $this->orderbystr, $this->conn) or die(mysql_error()); } return ($res); } } $src = new mysrc($server, $user, $pw, $db, $table, $options); $src->select(trim($_POST['FieldName']),trim($_POST['Like'])); ?> the reason you were getting the error is b/c the class wasn't defined yet so php was like, 'mysrc? wtf is this? gtfo!' (sorry, red bull morning. stranger mood than normal). hope that helps. Like I said, this is what I'm seeing off the cuff and, I'm in no way offical support, I stumbled across your post and have a helpful nature.
Hi Joseph,
Thanks again for your reply. However, Its still not ok.... Some details first may help. I am using the 'country.sql' I am using a 'standard' drasticSrcMySQL.class.php I have modified the ExampleGrid3.php as index1.php I think there are two areas I do not understand... 1st, getting the $_POST to be seen by the 'class mysrc' and the 'protected function select' 2nd, getting the $_POST to be seen by 'DrasticGrid.js' in the query that is run on line 34 of index1.php: var thegrid = new drasticGrid('grid1', {pathimg:"img/", sort:"a"}); MY FILES My index.php: <form name="columnname" method='post' action="index1.php"> <select name="searchstring"> <option value="Europe">Europe</option> <option value="Africa">Africa</option> <option value="Asia">Asia</option> <option value="Oceania">Oceania</option> </select> <input style="font-size:12px;" type="Submit" value="Show"> </form> My index1.php: <?php define("PATHDRASTICTOOLS", ""); include(PATHDRASTICTOOLS."mysqlconfig.php"); include(PATHDRASTICTOOLS."drasticSrcMySQL.class.php"); class mysrc extends drasticsrcmysql { protected function select($SearchString){ if ( $SearchString != '') { $res = mysql_query("SELECT * FROM country WHERE `Continent` = '$SearchString'" . $this->orderbystr, $this->conn) or die(mysql_error()); } else { $res = mysql_query("SELECT * FROM country" . $this->orderbystr, $this->conn) or die(mysql_error()); } return ($res); } } $SearchString = "$_POST[searchstring]"; $src = new mysrc($server, $user, $pw, $db, $table, $options); $src->select($SearchString); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <link rel="stylesheet" type="text/css" href="css/ExampleGrid2.css"/> <link rel="stylesheet" type="text/css" href="css/grid_default.css"/> <title>ExampleGrid3</title> </head><body> <script type="text/javascript" src="js/mootools.v1.11.js"></script> <script type="text/javascript" src="js/drasticGrid.js"></script> <div id="grid1"></div> <script type="text/javascript"> var thegrid = new drasticGrid('grid1', {pathimg:"img/", sort:"a"}); </script> </body></html> I am keeping this example simple, however, I actually wish to pass: 1. A ColumnName (Field from Db) 2. A Condition (equals or like) 3. A SearchString (Query for rows) It would make the grid, very versitile. Any takers? If someone feels they can do it for a nominal fee, I will try to oblige. Cheers from Australia... Rick
Passing additional variables to the PHP code is not supported at this moment. This is because of ths current architecture where Ajax calls generated from javascript call the PHP code.
For more background information, read an an earlier discussion in this forum: http://www.phpclasses.org/discuss/package/3444/thread/8/ However, the coming release (0.6.13) will have an option "addparams" in javascript to add additional parameters to the PHP requests. This may be used for this kind of functionality. |
info at phpclasses dot org.
