SQL Problem with PHP

Sharky Forums


Results 1 to 5 of 5

Thread: SQL Problem with PHP

  1. #1
    Great White Shark vertices's Avatar
    Join Date
    Sep 2000
    Location
    Palm Coast, FL
    Posts
    6,001

    SQL Problem with PHP

    I need to use 4 SQL SELECT statements on one PHP Page. I've been trying this:
    Code:
    <?php 
    
    if (isset($HTTP_GET_VARS["benchmark"])){
    	$benchmark = $HTTP_GET_VARS["benchmark"];
    } // end if
    
    if ($benchmark == "3dmark01") {
     $benchname= "2001";
    }
    
    if ($benchmark == "3dmark03") {
     $benchname= "2003";
    }
    
    if ($benchmark == "3dmark05") {
     $benchname= "2005";
    }
    
    $dbServer = "localhost"; 
    $dbDatabase = "xxxx"; 
    $dbUser = "xxxx"; 
    $dbPass = "xxxx"; 
    $sConn = @mysql_connect($dbServer, $dbUser, $dbPass)
    or die("Couldn't connect to database server"); 
    $dConn = @mysql_select_db($dbDatabase, $sConn)
    or die("Couldn't connect to database $dbDatabase"); 
      
     	$query  = "SELECT  MIN(score), MAX(score), AVG(score) FROM $benchmark";
    	$result = mysql_query($query) or die("Error: " . mysql_error()); 
    	
    	$query2  = "SELECT cpu, MIN(score), MAX(score), AVG(score) FROM $benchmark WHERE cpu="intel" GROUP BY cpu";
    	$result2 = mysql_query($query2) or die("Error: " . mysql_error()); 
            
            $query3  = "SELECT cpu, MIN(score), MAX(score), AVG(score) FROM $benchmark WHERE cpu="amd" GROUP BY cpu";
    	$result3 = mysql_query($query3) or die("Error: " . mysql_error()); 
    	
    	$query4  = "SELECT video, MIN(score), MAX(score), AVG(score) FROM $benchmark GROUP BY video";
    	$result4 = mysql_query($query4) or die("Error: " . mysql_error());

    I am using these on different parts of the page. The page is basically a large averages page.

    I currently get the following error when I add more than 1 of these SELECT statements:

    Parse error: parse error, unexpected T_STRING

    This error always is on the line where $query2 starts.

    It works fine with only the first statement but when I add the second I get the error.

    Anyone have a solution for me?

    Thanx in advance.
    Last edited by vertices; 10-04-2004 at 01:01 AM.

  2. #2
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704
    It looks like you are terminating your query2 string before you intend to (with the quote before "intel" on that line). You do the same thing on your query3 line.

    Might try:

    $query2 = "SELECT cpu, MIN(score), MAX(score), AVG(score) FROM $benchmark WHERE cpu=\"intel\" GROUP BY cpu";

    or, if I'm not mistaken, you could just replace the double-quotes with single-quotes inside the string.

    It's been a long time since I've worked with sql, though, so no promises.
    Nick_B
    Currently running Ubuntu and Windows 7.

  3. #3
    Great White Shark vertices's Avatar
    Join Date
    Sep 2000
    Location
    Palm Coast, FL
    Posts
    6,001
    Originally posted by Nick_B
    It looks like you are terminating your query2 string before you intend to (with the quote before "intel" on that line). You do the same thing on your query3 line.

    Might try:

    $query2 = "SELECT cpu, MIN(score), MAX(score), AVG(score) FROM $benchmark WHERE cpu=\"intel\" GROUP BY cpu";

    or, if I'm not mistaken, you could just replace the double-quotes with single-quotes inside the string.

    It's been a long time since I've worked with sql, though, so no promises.
    Jeez, I had been working on that site for over 10 hours and completely missed that syntax error. Thankee Thankee.

  4. #4
    Hammerhead Shark
    Join Date
    Mar 2001
    Location
    Littleton, CO
    Posts
    2,704
    Originally posted by vertices
    Jeez, I had been working on that site for over 10 hours and completely missed that syntax error. Thankee Thankee.
    Hey no problem.

    And don't feel bad, I've done much worse.
    Nick_B
    Currently running Ubuntu and Windows 7.

  5. #5
    Ex-*** kid A's Avatar
    Join Date
    Sep 2000
    Location
    Norway
    Posts
    5,322
    Just as an aside, $HTTP_*_VARS is deprecated. You are encouraged to use $_GET, $_POST etc according to the PHP manual. Although I am having problems with $_SESSION myself
    Now listening to various rock and metal
    143rd member to join Sharkyforums.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •