1

I have a seemly silly question but serious headache to ask you. I'm not quite a new sql but not too new. I coded many sqls but never found a problem like this before. The query can result in phpmysql but I can't get any row from PHP. Here's my code :

SELECT reb_dis, reb_title, reb_detail 
FROM rate_eb WHERE reb_abook <= '77' 
AND ABS(DATEDIFF('2013-09-09','2013-09-05'))>=reb_mn
AND '2013-09-05' BETWEEN reb_date1 AND reb_date2 
AND '2013-09-09' BETWEEN reb_date1 
AND reb_date2

So this is how I wrote my PHP:

$sql_eb="SELECT reb_dis, reb_title, reb_detail 
FROM rate_eb WHERE reb_abook <= '77' 
AND ABS(DATEDIFF('2013-09-09','2013-09-05'))>=reb_mn 
AND '2013-09-05' BETWEEN reb_date1 AND reb_date2 
AND '2013-09-09' BETWEEN reb_date1 AND reb_date2";
$result_eb=mysql_query($sql_eb);
$rec_eb=mysql_fetch_array($result_eb);

But I can't get any of the value from DB. No matter I tried:

<?
echo $rec_eb[reb_dis];
echo $rec_eb[reb_title];
echo $rec_eb[reb_detail];
?>

None of the above data shows. While I can get the data from other simpler query. So may I beg you guys explanations why this lines of query doesn't show anything??? And also how to get its data.

Regards,

Wilf
  • 2,297
  • 5
  • 38
  • 82
  • 2
    `echo $rec_eb['reb_dis'];` ? BTW, `mysql` is deprecated, use either PDO or `mysqli`. And if missing quotes are just typos run query directly on mysql server and see if it returns results. Using short tags like this is also bad idea, it may mix-up with `xml`. – Leri Jun 19 '13 at 06:33
  • 4
    `mysql_query($sql_eb) or die(mysql_error());` ? – Rikesh Jun 19 '13 at 06:34
  • 2
    You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Jun 19 '13 at 06:34
  • @PLB, The result returns correctly in phpmyadmin. – Wilf Jun 19 '13 at 06:42
  • Can you show your DB and query in SQL Fiddle svp? In that way I can help you easier. – Matheno Jun 19 '13 at 06:49

1 Answers1

2

You have to iterate the result using while loop and put index inside '

while($rec_eb=mysql_fetch_array($result_eb)) {
     echo $rec_eb['reb_dis'];
     echo $rec_eb['reb_title'];
     echo $rec_eb['reb_detail'];
}

Also change <? to <?php.

Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100