SELECT rugnummer, achternaam, tbl_kaarten.ikoon, CASE
WHEN aantaldoelpunten = 1 THEN '<img src="1bal.png" alt="icon" />'
WHEN aantaldoelpunten = 2 THEN '<img src="2bal.png" alt="icon" />'
WHEN aantaldoelpunten = 3 THEN '<img src="3bal.png" alt="icon" />'
WHEN aantaldoelpunten = 4 THEN '<img src="4bal.png" alt="icon" />'
WHEN aantaldoelpunten = 5 THEN '<img src="5bal.png" alt="icon" />'
WHEN aantaldoelpunten = 6 THEN '<img src="6bal.png" alt="icon" />'
WHEN aantaldoelpunten = 7 THEN '<img src="7bal.png" alt="icon" />'
WHEN aantaldoelpunten = 8 THEN '<img src="8bal.png" alt="icon" />'
WHEN aantaldoelpunten = 9 THEN '<img src="9bal.png" alt="icon" />'
END AS aantaldoelpunten FROM tbl_opstellingn
LEFT JOIN tbl_spelers ON tbl_opstellingn.spelerID = tbl_spelers.spelerID
LEFT JOIN ktbl_club_speler ON tbl_opstellingn.spelerID = ktbl_club_speler.spelerID
LEFT JOIN tbl_kaarten ON tbl_opstellingn.spelerID = tbl_kaarten.spelerID
LEFT JOIN
( SELECT COUNT(*) AS aantaldoelpunten, tbl_doelpunten.spelerID
FROM tbl_doelpunten
LEFT JOIN tbl_opstellingn ON tbl_doelpunten.spelerID = tbl_opstellingn.spelerID
WHERE thuis_uit = 'thuis' AND tbl_doelpunten.wedstrijdID = '109'
GROUP BY tbl_opstellingn.opstellingpos ) a
ON tbl_spelers.spelerID = a.spelerID WHERE tbl_opstellingn.wedstrijdID = '109' AND thuis_uit = 'thuis' AND clubID = '11' limit 0, 11
Wanneer ik deze query uitvoer in MySQL gaat alles prima. Maar zodra ik hem op mn site laat zien krijg ik de volgende error:
MySQL Error#: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') f ON tbl_spelers.spelerID = f.spelerID WHERE tbl_opstellingn.wedstrijdID = '10' at line 2
Ik begrijp er niets meer van. Weet iemand wat er aan de hand is?
Toevoeging op 23/10/2013 23:14:03:
Ik heb nu de spatie tussen "(" en "select count" weggehaald. Nu krijg ik geen 1064-error maar. MAar bij het testen van de pagina krijg ik nu de volgende error:
"Parse error: syntax error, unexpected '1' (T_LNUMBER) in C:\xampp\htdocs\................php on line 261"
Ik kan beide vragen/problemen niet helemaal plaatsen. De tekst die in de foutmelding van je query krijgt staat niet in de query. Dus daar kunnen we verder niets mee (ofwel: plaats de goede code).
De tweede foutmelding is ook niets over te zeggen omdat dat een php probleem betreft (waarschijnlijk een quote teveel of te weinig), maar je laat geen php code zien.
PHP is (nog) niet mijn sterkste kant (doe daarom ook veel met dreamweaver, excuses daarvoor)
Bedoel je dit?
mysql_select_db($database_hallo, $hallo);
$query_RSopstellingplusTHUIS = "SELECT rugnummer, achternaam, tbl_kaarten.icon, CASE WHEN aantaldoelpunten = 1 THEN '<img src="1bal.png" alt="icon" />' WHEN aantaldoelpunten = 2 THEN '<img src="2bal.png" alt="icon" />' WHEN aantaldoelpunten = 3 THEN '<img src="3bal.png" alt="icon" />' WHEN aantaldoelpunten = 4 THEN '<img src="4bal.png" alt="icon" />' WHEN aantaldoelpunten = 5 THEN '<img src="5bal.png" alt="icon" />' WHEN aantaldoelpunten = 6 THEN '<img src="6bal.png" alt="icon" />' WHEN aantaldoelpunten = 7 THEN '<img src="7bal.png" alt="icon" />' WHEN aantaldoelpunten = 8 THEN '<img src="8bal.png" alt="icon" />' WHEN aantaldoelpunten = 9 THEN '<img src="9bal.png" alt="icon" />' END AS aantaldoelpunten FROM tbl_opstellingn LEFT JOIN tbl_spelers ON tbl_opstellingn.spelerID = tbl_spelers.spelerID LEFT JOIN ktbl_club_speler ON tbl_opstellingn.spelerID = ktbl_club_speler.spelerID LEFT JOIN tbl_kaarten ON tbl_opstellingn.spelerID = tbl_kaarten.spelerID LEFT JOIN (SELECT COUNT( * ) AS aantaldoelpunten, tbl_doelpunten.spelerID FROM tbl_doelpunten LEFT JOIN tbl_opstellingn ON tbl_doelpunten.spelerID = tbl_opstellingn.spelerID WHERE thuis_uit = 'thuis' AND tbl_doelpunten.wedstrijdID = '109' GROUP BY tbl_opstellingn.opstellingpos )a ON tbl_spelers.spelerID = a.spelerID WHERE tbl_opstellingn.wedstrijdID = '109' AND thuis_uit = 'thuis' AND clubID = '11' ";
$query_limit_RSopstellingplusTHUIS = sprintf("%s LIMIT %d, %d", $query_RSopstellingplusTHUIS, $startRow_RSopstellingplusTHUIS, $maxRows_RSopstellingplusTHUIS);
$RSopstellingplusTHUIS = mysql_query($query_limit_RSopstellingplusTHUIS, $hallo) or die(mysql_error());
$row_RSopstellingplusTHUIS = mysql_fetch_assoc($RSopstellingplusTHUIS);
if (isset($_GET['totalRows_RSopstellingplusTHUIS'])) {
$totalRows_RSopstellingplusTHUIS = $_GET['totalRows_RSopstellingplusTHUIS'];
} else {
$all_RSopstellingplusTHUIS = mysql_query($query_RSopstellingplusTHUIS);
$totalRows_RSopstellingplusTHUIS = mysql_num_rows($all_RSopstellingplusTHUIS);
}
$totalPages_RSopstellingplusTHUIS = ceil($totalRows_RSopstellingplusTHUIS/$maxRows_RSopstellingplusTHUIS)-1;
Kijk, nu wordt het duidelijk waar het probleem zit. Je gebruikt allerlei quotes door elkaar en dat gaat zo op een gegeven moment fout. Kijk naar de kleuren en je ziet het probleem:
<?php
$query_RSopstellingplusTHUIS = "SELECT rugnummer, achternaam, tbl_kaarten.icon,
CASE WHEN aantaldoelpunten = 1 THEN '<img src="1bal.png" alt="icon" />'
WHEN aantaldoelpunten = 2 THEN '<img src="2bal.png" alt="icon" />'
WHEN aantaldoelpunten = 3 THEN '<img src="3bal.png" alt="icon" />'
WHEN aantaldoelpunten = 4 THEN '<img src="4bal.png" alt="icon" />'
WHEN aantaldoelpunten = 5 THEN '<img src="5bal.png" alt="icon" />'
WHEN aantaldoelpunten = 6 THEN '<img src="6bal.png" alt="icon" />'
WHEN aantaldoelpunten = 7 THEN '<img src="7bal.png" alt="icon" />'
WHEN aantaldoelpunten = 8 THEN '<img src="8bal.png" alt="icon" />'
WHEN aantaldoelpunten = 9 THEN '<img src="9bal.png" alt="icon" />' END AS aantaldoelpunten
FROM tbl_opstellingn
LEFT JOIN tbl_spelers ON tbl_opstellingn.spelerID = tbl_spelers.spelerID
LEFT JOIN ktbl_club_speler ON tbl_opstellingn.spelerID = ktbl_club_speler.spelerID
LEFT JOIN tbl_kaarten ON tbl_opstellingn.spelerID = tbl_kaarten.spelerID
LEFT JOIN (
SELECT COUNT( * ) AS aantaldoelpunten, tbl_doelpunten.spelerID
FROM tbl_doelpunten
LEFT JOIN tbl_opstellingn ON tbl_doelpunten.spelerID = tbl_opstellingn.spelerID
WHERE thuis_uit = 'thuis' AND tbl_doelpunten.wedstrijdID = '109'
GROUP BY tbl_opstellingn.opstellingpos
)a ON tbl_spelers.spelerID = a.spelerID
WHERE tbl_opstellingn.wedstrijdID = '109'
AND thuis_uit = 'thuis'
AND clubID = '11' ";
?>
En ook een beetje handiger op geschreven want bovenstaande query op 1 regel zetten is natuurlijk complete waanzin.
Je ziet niet dat de query geopend wordt door een dubbele quote en dat de dubbele quote in de case statement het weer afsluit? Die dubbele quote tussen src= en 1bal.png.
OK, dus ik mag tussen src= en 1 bal.png geen dubbele quotes gebruiken en die moet ik vervangen door enkele?
Toevoeging op 24/10/2013 00:15:39:
Ik heb nu alle dubbele quotes weggehaald bij de case statement. Gevolg is geen rode tekst meer in de code. Echter nog wel een error bij testen. Namelijk:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1bal.png' alt='icon' />' WHEN aantaldoelpunten = 2 THEN '
Toevoeging op 24/10/2013 00:24:41:
Nou, volgens mij is het gelukt.
"SELECT rugnummer, achternaam, tbl_kaarten.icon, CASE WHEN aantaldoelpunten = 1 THEN '<img src=1bal.png alt=icon />'
Helemaal geen quotes (dubbele of enkele) meer om 1bal.png en icon heen.
Ik ga morgen verder kijken. Erwin. hartstikke bedankt!
<?php require_once('Connections/hallo.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
mysql_select_db($database_hallo, $hallo);
$query_RSTHUISopstelling = "
SELECT rugnummer, achternaam, tbl_kaarten.icon, aantaldoelpunten
FROM tbl_opstellingn LEFT JOIN tbl_spelers ON tbl_opstellingn.spelerID = tbl_spelers.spelerID
LEFT JOIN ktbl_club_speler ON tbl_opstellingn.spelerID = ktbl_club_speler.spelerID
LEFT JOIN tbl_kaarten ON tbl_opstellingn.spelerID = tbl_kaarten.spelerID
LEFT JOIN (
SELECT COUNT(*) AS aantaldoelpunten, tbl_doelpunten.spelerID FROM tbl_doelpunten
LEFT JOIN tbl_opstellingn ON tbl_doelpunten.spelerID = tbl_opstellingn.spelerID
WHERE thuis_uit = 'thuis'
AND tbl_doelpunten.wedstrijdID = '109'
GROUP BY tbl_opstellingn.opstellingpos ) f ON tbl_spelers.spelerID = f.spelerID
WHERE tbl_opstellingn.wedstrijdID = '109' AND thuis_uit = 'thuis'
AND clubID = '11' limit 0, 11";
$RSTHUISopstelling = mysql_query($query_RSTHUISopstelling, $hallo) or die(mysql_error());
$row_RSTHUISopstelling = mysql_fetch_assoc($RSTHUISopstelling);
$totalRows_RSTHUISopstelling = mysql_num_rows($RSTHUISopstelling);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
#apDiv1 {
position: absolute;
width: 250px;
height: 350px;
z-index: 1;
left: 11px;
top: 16px;
}
</style>
</head>
<body>
<div id="apDiv1">
<table border="0" cellpadding="0" cellspacing="0">
<?php do { ?>
<tr>
<td width="25" align="center"><?php echo $row_RSTHUISopstelling['rugnummer']; ?></td>
<td width="125" align="left"><?php echo $row_RSTHUISopstelling['achternaam']; ?></td>
<td width="50" align="right"><?php echo $row_RSTHUISopstelling['icon']; ?></td>
<td width="50" align="right"><?php echo $row_RSTHUISopstelling['aantaldoelpunten']; ?></td>
</tr>
<?php } while ($row_RSTHUISopstelling = mysql_fetch_assoc($RSTHUISopstelling)); ?>
</table>
</div>
</body>
</html>
<?php
mysql_free_result($RSTHUISopstelling);
?>
Bovenstaande is mijn oefenpagina.
Ik heb de CASE-statement uit mijn SQL-query gesloopt. Nu geeft kolom aantaldoelpunten gewoon het numerieke aantal doelpunten dat een speler gescoord heeft.
Waar moet jouw code om middels php tekst aan de numerieke waarde te plakken dan komen te staan?
<?php
$result= $mysqli->query("SELECT aantaldoelpunten FROM"; // .... en het ressie;
while ($row = $result->fetch_assoc()) {
echo '<img src="' . $row['aantaldoelpunten'] . 'bal.png" alt="icon" />';
}
?>
En wat bedoel je met ".... en het ressie"? moet ik daar de hele sql-query weer zetten?