PHP MYSQL data fetching problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kosaks
    New Member
    • May 2010
    • 10

    PHP MYSQL data fetching problem

    Hello again

    i would like to ask why i get null values from mysql database. This is my code

    Code:
    $SqlQuery->OpenConnection("localhost","sample","test");
    $SqlQuery->SelectDatabase("sampleDbase");
    $sql = "SELECT company_id FROM `companies` WHERE company_name = \'Jet Stream\'";
    echo($SqlQuery->GetResults($sql));
    Code:
    function GetResults($sql)
    {
     $val;
     $result = mysql_query($sql);
     while($row = mysql_fetch_object($result))
     {
      $val = $row->password;
     }
     return $val;
    }
    I dont know why my php code return null values. but when i try my query on mysql database i shows results. Can anyone tell me why i get null values?

    thanks
    Last edited by Niheel; Jun 28 '11, 01:29 PM.
  • Rekha Kumaran
    New Member
    • Jan 2011
    • 30

    #2
    Make sure whether u have values 'Jet Stream' in company_name field!!!

    Try this query
    SELECT company_id FROM `companies` WHERE company_name = \'%Jet Stream\%'"

    Comment

    • nathj
      Recognized Expert Contributor
      • May 2007
      • 937

      #3
      Alternatively you could try:
      Code:
      $sql = "SELECT company_id FROM `companies` WHERE company_name = 'Jet Stream'"
      theother option is to set up a variable
      Code:
      $companyname= "Jet Stream";
      $sql = "SELECT company_id FROM `companies` WHERE company_name = '$companyname'";
      Using a variable like this makes the code much more reusable.

      Cheers
      nathj
      Last edited by nathj; Jun 29 '11, 07:22 AM. Reason: minor addition to the idea

      Comment

      Working...