sql statement being outputed rather than executed!

Discussion in 'PHP' started by billybrag, Feb 17, 2006.

  1. #1
    I have a situation where by the following code is outputing the query rather than actually executing it.

    Im noob to this so its probably something stupid..

    
    <?PHP
          $display .= "<table>";
          $sql = "SELECT * FROM job_jobcategories";
          $sql_res = mysql_query($sql);
    
          while ($sql_array = mysql_fetch_array($sql_res)){
          $jobcat = $sql_array[jobcategory];
          $query = "SELECT jobcategory, COUNT(*) FROM job_post WHERE jobcategory = $jobcat";
         
          $display .= "
          <tr>
          <td>$jobcat</td>
          <td>($query)</td>
          </tr>
          ";
          }
     
          $display .= "</table>";
    
          echo $display;
          ?> 
    
    
    
    PHP:
    the line that is not working is the $query

    the first part (not written by me) works ok.

    I have attached a screenshot of what is output
     

    Attached Files:

    billybrag, Feb 17, 2006 IP
  2. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #2
    You aren't calling a mysql_query() on it.
     
    digitalpoint, Feb 17, 2006 IP
  3. billybrag

    billybrag Peon

    Messages:
    324
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how would i do that?

    and thanks for the rediculously fast reply :)
     
    billybrag, Feb 17, 2006 IP
  4. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #4
    Same way you are doing it in the first part on the $sql variable.
     
    digitalpoint, Feb 17, 2006 IP
  5. billybrag

    billybrag Peon

    Messages:
    324
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    so something like..

    
    <?PHP
          $display .= "<table>";
          $sql = "SELECT * FROM job_jobcategories";
          $sql_res = mysql_query($sql);
    
          while ($sql_array = mysql_fetch_array($sql_res)){
          $jobcat = $sql_array[jobcategory];
          $query = "SELECT jobcategory, COUNT(*) FROM job_post WHERE jobcategory = $jobcat";
          $sql_query = mysql_query($query);
         
          $display .= "
          <tr>
          <td>$jobcat</td>
          <td>($sql_query)</td>
          </tr>
          ";
          }
     
          $display .= "</table>";
    
          echo $display;
          ?> 
    PHP:
     
    billybrag, Feb 17, 2006 IP
  6. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,334
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #6
    Yeah, that would execute the query (and output it).
     
    digitalpoint, Feb 17, 2006 IP