I'm using my client's mysql database. My client has form search fields: voltage, power, size, material and length. They want the visitor to enter any combination of these and get some results. I've tried using AND and we get no results, I tried using OR and got all the records no matter what. What am I missing? The form data is turned into $POST_variables like $pvoltage. Any ideas on how to do this?
WHERE
(voltage = '$pvoltage' AND power_kw = '$ppower' AND size LIKE '$psize%' AND
material = '$pmat' AND immers_length LIKE '$plength%')
Also tried it with OR - gave me everything instead of just the results where there was data. This gives me nothing.
This finally worked for me in the WHERE statement:
IF('$pvoltage' ='',voltage LIKE '%',voltage LIKE '$pvoltage')
Related
I'm needing to create more than 1 filter to run a query to cut down the number of results found.
I am trying to do these 3 queries at once using RethinkDB for php found here
The code I am running is:
$query = \r\table('payments')->filter(
\r\row('forwarded')->eq('1'),
\r\row('bad_callbacks_sent')->lt("1"),
\r\row('confirmations')->le('7')
)->run($this->conn);
I've just also tried doing the following and it doesn't work (it's just showing all where the first argument - where forwarded = 1. It's only doing the first filter:
$query = \r\table('payments')
->filter(\r\row('forwarded')->eq('1'))
->filter(\r\row('bad_callbacks_sent')->lt("6"))
->filter(\r\row('confirmations')->le("7"))
->run($this->conn);
But it doesn't seem to be doing what I ask.
I need to make it get:
Where forwarded == 1
Where bad_callbacks_sent < 1
Where confirmations <= 7
I found this the following code from here, which shows that you can chain them in js but I'm wondering about PHP:
r.db('items').table('tokens')
.filter(r.row('valid_to').gt(r.now()))
.filter(r.row["processed"] == False)
Any ideas?
Okay so it turns out, the issue was not with my new code:
$query = \r\table('payments')
->filter(\r\row('forwarded')->eq('1'))
->filter(\r\row('bad_callbacks_sent')->lt(6))
->filter(\r\row('confirmations')->le(7))
->run($this->conn);
But with the variable type.
In my database, it was stored as an int but I was trying to read it via (le("7")) a string.
The above code works fine :)
It allows you to filter more than 1 query in retihnkdb for php.
Make sure you check your variable types in your database!
RethinkDB is very sensitive to what types they're.
Hope I save you some time.
I want to load data from a SQLite database in PHP using Atlas.Orm.
When I run the following snippet, I get a set of 1773 results, but each result is the same!
$atlas = Atlas::new('sqlite:[Path To Database]');
$result = $atlas->select(Stop::class)->fetchRecords();
Can anyone tell me whats wrong here?
After several hours of desperation, I found the issue by myself. The ORM needs the PRIMARY_KEY constant in the corresponding *Table class to be set, otherwise fetching records will fail like this.
I have come across a strange problem, which im trying to solve for quite some time now but can´t find any solution to this.
I am generating some lines with information which each of includes one checkbox. I have the following code in PHP which checks if a certrain entry exists, if so the checkbox is checked.
$sql = "SELECT COUNT(*) anz FROM jubilaeum WHERE jahr='".$Jahr."' AND mon='".$num."' AND AdrNr='".$RS1_row["AdrNr"]."' AND type='1'";
$rs_erledigt = $db->prepare($sql);
$rs_erledigt->execute();
$row = $rs_erledigt->fetch();
$anz = $row["anz"];
The Code generates me the following SQL Query:
SELECT COUNT(*) anz FROM jubilaeum WHERE jahr='2019' AND mon='5' AND AdrNr='14061' AND type='1'
PHPMyAdmin Query & Result
Now i am using a basic IF to check if there are any records found so i can check a checkbox
<input type="checkbox" name="mychk" id="mychk" value="somevalue" <?php if($anz>0) echo "checked"; ?> />
All checkboxes which have a proper entry in my DB are checked, except the very first one generated, i can swap the boxes around at free will, the first one never gets checked.
I tried to use the $row["Anz"] directly in my IF, didn´t fix the problem.
I think that PHP doesnt interpret the returned value of my query correctly, but i am clueless about how to fix this.
Did someone encounter similar problems and can help me with this?
Im new to posting in here, so please tell me if you need some more information.
Thanks in advance!
Edit: I just tried to change the Query from COUNT(*) to if(COUNT(*)>0,'ja','nein') while also changing the if to if($anz=="ja")
the value of $anz still remains empty.
I found the solution. My issue was a second fetch on my Query. After removing it, everything works fine.
I'm not getting the result I need and I'm sure it is a small problem here.
I have a column(mfg_req) in my database which have a record with 10M.
My variable in php does have the text 10M40SABCDE.
What I want is to search in my table and get the results starting with this variable.
My MYSQL query does look like below but no results:
SELECT * FROM specific_req WHERE mfg_req LIKE '10M40SABCDE%'
I also tried the below query but no results
SELECT * FROM specific_req WHERE mfg_req LIKE '%10M40SABCDE%'
Also tried the below but it shows me all records except the one I need with 10M
SELECT * FROM specific_req WHERE '10M40SABCDE' LIKE CONCAT('%',mfg_req)
I have tried to put the % behind mfg_req but then it will show me all records including the one I need.
I cannot figure it out how to get the result I need. If someone can help me with my query I would appreciate it a lot.
Thanks!
Let's say:
$var = '10M40SABCDE';
...then your SQL statement must be:
$sql = "SELECT * FROM specific_req WHERE mfg_req LIKE '{$var}%'";
It would be best if you show a snippet of your code, too.
I would like to do search for advanced search. The Search feature has and/or for every category. User can choose any combination of and n or. Here i give the screenshot
I store the and/or into variable call $pil, $pil1,$pil2 and $pil3. And will put them in query. it's better than validate one by one every condition of and/or
So this is my query using postgresql in PHP
$query = pg_query("SELECT evaluationdate,onlinename,channel,topik,reviewername,sourceevaluation,evaluation
from AgentPerformance
where onlinename like '%".$VEOn1."%'
".$pil." reviewername like '%".$VERev1."%'
".$pil1." channel like '%".$VEChan1."%'
".$pil2."sourceevaluation like '%".$VESource1."%'
".$pil3."evaluationdate between '".$VEStart1."' and '".$VEEnd1."'");
EDIT :
The problem now, All the variables must not be empty or the query will be error. any way to trick this?
You've missed some spaces near sourceevaluation and evaluationdate
Try with this query :
$query = pg_query("SELECT evaluationdate,onlinename,channel,topik,reviewername,sourceevaluation,evaluation
from AgentPerformance
where onlinename like '%".$VEOn1."%'
".$pil." reviewername like '%".$VERev1."%'
".$pil1." channel like '%".$VEChan1."%'
".$pil2." sourceevaluation like '%".$VESource1."%'
".$pil3." evaluationdate between '".$VEStart1."' and '".$VEEnd1."'");
Simply. Use validation for each $pil whether it is empty or not. it makes me validate 4 times, but it solves the problem. The syntax error has been solved too