简体   繁体   中英

Undefined offset error when running SQL query

Each time I run the the SQL statement:

SELECT * FROM tbl_accident WHERE progress = 'on hire' AND progress = 'vd'

But it returns an error:

Notice: Undefined offset: 2 in C:\\xampp\\htdocs\\newclaim\\cases.php on line 139
Notice: Undefined offset: 1 in C:\\xampp\\htdocs\\newclaim\\cases.php on line 139

Alternatively when I run:

SELECT * FROM tbl_accident WHERE progress = 'on hire';

or

SELECT * FROM tbl_accident WHERE progress = 'vd';

There is no problem. What am I doing wrong? The code at line 138-140 reads:

<td><?php $caseOpen = explode("/", $row_cases['caseOpen']); 
  $caseOpen = $caseOpen[2].'/'.$caseOpen[1].'/'.$caseOpen[0]; 
  echo $caseOpen;?></td>

try

SELECT * FROM tbl_accident WHERE progress='on hire' OR progress='vd'

You used AND instead of OR in your query. Using AND will never return any result because progress can't be vd and on hire at the same time.

Please check your sql. You are using progress in where clause more than on time using AND. YOu can use OR instead of AND

You are currently always getting 0 rows returned from your select.

Try this:

SELECT * FROM tbl_accident WHERE progress in ('on hire', 'vd')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM