|
-
Great White Shark
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.
-
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.
-
Great White Shark
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.
-
-
Ex-***
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
-
Forum Rules
|
|