same query return rows in mysql but not on php page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kkshansid
    New Member
    • Oct 2008
    • 232

    same query return rows in mysql but not on php page

    same query return rows in mysql but not on php page
    Code:
    while($rs = mysql_fetch_array($sql2))
    {
    $town=$rs[town];
    $q="select * from institute where address like '%".$town."%'";//this query
    //echo $town;
    echo  $q;//same query return rows in mysql
    //exit();
    $sql3 = mysql_query($q);
    
    
    if(!$sql3) { echo mysql_error();}
    $rowcount= mysql_num_rows($sql3) ;
    echo $rowcount;
    while($rs1 = mysql_fetch_array($sql3))
    {
    echo 'l2';
    ?>
    select * from institute where address like '%SOPORE %' works in mysql but return 0 row count in php code
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    In the query you posted, there is a space before the second %. Is that also in the query that returns rows?
    Code:
    '%SOPORE %'
    Try removing that. You can use the trim function on the $town variable to do that automatically for all values it may hold.

    P.S.
    Unless you have a constant named "town":
    [code=php]$town=$rs[town];
    // Should be
    $town=$rs['town'];[/code]
    If you turn error reporting on, you would see why. (Which you should always do when you are developing/debugging your code.

    Comment

    • kkshansid
      New Member
      • Oct 2008
      • 232

      #3
      thanx it was due to trim function

      Comment

      Working...