Beste forumleden,

Ik wil uitslagen en statistieken van gespeelde voetbalwedstrijden laten zien op mijn site.
Nu heb ik een vraag m.b.t. presentatie van data (in tabelvorm) uit een db op mn website.

Dus bijvoorbeeld van de wedstrijd ADO - PSV wil ik de opstelling van ADO als volgt laten zien

Resultaat SQL-query:

rugnummer 	achternaam 	kaarten 	aantaldoelpunten
1	Coutinho 	NULL	NULL
15	Malone 	<img src="geel.png" alt="icon" /> 	NULL
3	Wormgoor 	NULL	NULL
18	Beugelsdijk 	NULL	NULL
8	Meijers 	<img src="geel.png" alt="icon" /> 	NULL
7	Jansen 	NULL	NULL
14	Visser 	NULL	NULL
10	Toornstra 	NULL	NULL
11	Chery 	<img src="geel.png" alt="icon" /> 	NULL
36	Vicento 	NULL	<img src="goal.png" alt="icon" />
9	Poepon 	NULL	NULL


Dus naast de kolommen rugnummers en achternaam ook twee kolommen met informatie of de speler een kaart gekregen heeft of gescoord heeft.

Nu gaat het me om de presentatie van deze resultaten van de query. Ik wil rugnummers en namen aan de linkerkant en kaarten en doelpunten aan de rechterkant. Tot zover geen probleem.

Alleen: nu wil ik graag dat wanneer een speler wel een kaart heeft gekregen maar niet heeft gescoord, het plaatje van de kaart helemaal naar rechts uitgelijnd is. (En dus eigenlijk op de plek van het plaatje van het doelpunt staat (als de speler die gemaakt had)). Want nu staat dat plaatje van die kaart zo lelijk in het midden van de regel.

Ik hoop dat jullie begrijpen wat ik bedoel...

Is dat mogelijk? En zo ja hoe?
Je moet natuurlijk wel even goed kijken wat je in de PHP zet. Zoals je nu laat zie staat de if-statement gewoon in je HTML en wordt dus niet als PHP uitgevoerd. Zet hier dus <?php en ?> om heen.


[edit]

<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>rugnummer</td>
      <td>achternaam</td>
      <td>icon</td>
      <td>aantaldoelpunten</td>
    </tr>
    <?php
		while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS))
		{
			echo '<tr>'.
			'<td>' . $row_RSopstellingTHUIS['rugnummer'] . '</td>'.
			'<td>' . $row_RSopstellingTHUIS['achternaam'] . '</td>';
			if($doelpunten > 0) {
				echo '<td>' . $row_RSopstellingTHUIS['icon'] . '</td>'.
				'<td>'. $row_RSopstellingTHUIS['aantaldoelpunten'] . '</td>';
			} else {
				echo '<td colspan="2" align="right">' . $row_RSopstellingTHUIS['icon'] . '</td>';
			}
			echo '</tr>';
		}
      ?>
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($RSopstellingTHUIS);
?>

Code toegevoegd

PHPHulp gooit blijkbaar zelf achter elke ?> maar gewoon blindelings [/code]
Dit moet je zelf natuurlijk weer even weg halen.
[/edit]
Bij een while gebruik je altijd een {. Ik denk dat het zo moet:


<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>rugnummer</td>
      <td>achternaam</td>
      <td>icon</td>
      <td>aantaldoelpunten</td>
    </tr>
    <?php while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS)){ ?>
      <tr>
        <td><?php echo $row_RSopstellingTHUIS['rugnummer']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['achternaam']; ?></td>
        if($doelpunten > 0) {
        <td><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['aantaldoelpunten']; ?></td>
      <?php  } else { ?>
        <td colspan="2" align="right"><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
      <?php  } 
        } ?>
      </tr>
      
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($RSopstellingTHUIS);
?>
Ik ben dus aan het klooien met <?php en ?>, maar ik kom er niet uit. Ik kan ze er namelijk niet helemaal omheen zetten omdat er ook html (td etc) inzit. Dus dat gaat niet werken.


<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>rugnummer</td>
      <td>achternaam</td>
      <td>icon</td>
      <td>aantaldoelpunten</td>
    </tr>
    <?php do { ?>
    <?php } while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS)); ?>
      <tr>
        <td><?php echo $row_RSopstellingTHUIS['rugnummer']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['achternaam']; ?></td>
    <?php if($aantaldoelpunten > 0) ?> { 
        <td><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['aantaldoelpunten']; ?></td>
		}
     <?php else ?> { 
        <td colspan="2" align="right"><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
		}
      </tr>


Werkt ook niet. Ik heb echt geen flauw idee meer ho het moet. Op internet kan ik niets vinden over het gebruik van colspan in een dynamische situatie.
Jo Immanuel op 24/10/2013 15:39:22

Ik ben dus aan het klooien met <?php en ?>, maar ik kom er niet uit. Ik kan ze er namelijk niet helemaal omheen zetten omdat er ook html (td etc) inzit. Dus dat gaat niet werken.


Zie mijn voorbeeld hierboven

[edit]
Kijk trouwens zelf eens goed naar die accolades ( { } ) die kun je simpel binnen de php tags zetten.
Door steeds PHP te openen en weer te sluiten wordt het niet overzichtelijk.


<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>rugnummer</td>
      <td>achternaam</td>
      <td>icon</td>
      <td>aantaldoelpunten</td>
    </tr>
    <?php while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS)) { ?>
      <tr>
        <td><?php echo $row_RSopstellingTHUIS['rugnummer']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['achternaam']; ?></td>
    <?php if($aantaldoelpunten > 0) { ?> 
        <td><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['aantaldoelpunten']; ?></td>
       
     <?php } else { ?>
        <td colspan="2" align="right"><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <?php } // if-statement afsluiten ?>
      </tr>
<?php } // While afsluiten ?>
He Michael,


<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td>rugnummer</td>
      <td>achternaam</td>
      <td>icon</td>
      <td>aantaldoelpunten</td>
    </tr>
    <?php while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS)) { ?>
      <tr>
        <td><?php echo $row_RSopstellingTHUIS['rugnummer']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['achternaam']; ?></td>
    <?php if($aantaldoelpunten > 0) { ?>
        <td><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <td><?php echo $row_RSopstellingTHUIS['aantaldoelpunten']; ?></td>
      
     <?php } else { ?>
        <td colspan="2" align="right"><?php echo $row_RSopstellingTHUIS['icon']; ?></td>
        <?php } // if-statement afsluiten ?>
      </tr>
<?php } // While afsluiten ?>
      
  </table>
</div>
</body>
</html>
<?php
mysql_free_result($RSopstellingTHUIS);
?>


Geeft geen foutmeldingen. Maar als ik hem test op mijn testserver dan krijg ik het volgende:

11x de volgende tekst:
Notice: Undefined variable: aantaldoelpunten in C:\xampp\htdocs\site-TS\oefening1asqlopstellingcolspan3.php on line 70

Lijn 70 is de volgende regel: <?php if($aantaldoelpunten > 0) { ?>

Verder valt op dat bij de tabel de gele kaarten wel mooi naar rechts zijn uitgelijnd, alleen is het plaatje van het doelpunt niet meer te zien.
2 Opties:

1) Oplossen
2) Error uitzetten

Ik zou voor 1 gaan, maar dat is je eigen keuze.

1) Wat staat er in $aantaldoelpunten?

Als je 2 wilt gebruiken moet je dit bovenaan het script zetten:

<?php
error_reporting(0);
?>
He Frank,

$aantaldoelpunten wordt bepaald door een SQL-query.


$query_RSopstellingTHUIS = "
SELECT rugnummer, achternaam, tbl_kaarten.icon,  
CASE WHEN aantaldoelpunten = 1 THEN '<img src=1bal.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 ) f ON tbl_spelers.spelerID = f.spelerID 
WHERE tbl_opstellingn.wedstrijdID = '109' 
AND thuis_uit = 'thuis' 
AND clubID = '11' limit 0, 11
";


Als een speler gescoord heeft komt er een plaatje van een voetbal. (Op dit moment alleen nog maar een plaatje van 1 doelpunt, In de voorbeeldwedstrijd heeft er niemand meer dan 1 keer gescoord).
Staat dit stuk boven of onder het andere gedeelte? Volgens je server bestaat die variabele namelijk niet.
Staat er boven (line 34). Body-gedeelte begint bij line 57.

Wacht ik zal de hele code geven van de (oefen)pagina geven die ik nu heb.



<?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_RSopstellingTHUIS = "
SELECT rugnummer, achternaam, tbl_kaarten.icon,  
CASE WHEN aantaldoelpunten = 1 THEN '<img src=1bal.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 ) f ON tbl_spelers.spelerID = f.spelerID 
WHERE tbl_opstellingn.wedstrijdID = '109' 
AND thuis_uit = 'thuis' 
AND clubID = '11' limit 0, 11";
$RSopstellingTHUIS = mysql_query($query_RSopstellingTHUIS, $hallo) or die(mysql_error());
$row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS);
$totalRows_RSopstellingTHUIS = mysql_num_rows($RSopstellingTHUIS);
?>
<!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>
zie onder


Toevoeging op 24/10/2013 17:10:38:

Blijkbaar is mijn variabele aantaldoelpunten undefined.

Daarom heb ik $aantaldoelpunten = ''; toegevoegd


<body>
<div id="apDiv1">
  <table border="0" cellpadding="0" cellspacing="0">
    <tr>
      <td width="50" align="center">rugnummer</td>
      <td width="100" align="left">achternaam</td>
      <td width="50" align="right">icon</td>
      <td width="50" align="right">aantaldoelpunten</td>
    </tr>
     <?php
        while ($row_RSopstellingTHUIS = mysql_fetch_assoc($RSopstellingTHUIS))
        {
            echo '<tr>'.
            '<td>' . $row_RSopstellingTHUIS['rugnummer'] . '</td>'.
            '<td>' . $row_RSopstellingTHUIS['achternaam'] . '</td>';
            $aantaldoelpunten = '';
			if($aantaldoelpunten > 0) {
                echo '<td>' . $row_RSopstellingTHUIS['icon'] . '</td>'.
                '<td>'. $row_RSopstellingTHUIS['aantaldoelpunten'] . '</td>';
            } else {
                echo '<td colspan="2" align="right">' . $row_RSopstellingTHUIS['icon'] . '</td>';
            }
            echo '</tr>';
        }
      ?>
  </table>
</div>


Nu krijg ik geen error meldingen meer als ik de pagina test op de testserver, alleen nog maar de tabel. Echter: wat opvalt is dat er:
1. nog steeds geen doelpunten weergegeven worden (voor ik colspan gebruikte stond er achter Vicento een voetbal)
2. ik sinds ik colspan probeer te gebruiken er geen 11 spelers maar slechts 10 spelers worden getoond. Het eerste resultaat (keeper Coutinho) is weggevallen.
Beste Jo,
Als je nou eens rustig je code bekijkt.
Je geeft aan $aantaldoelpunten = '';

Als je nou
$aantaldoelpunten = $row_RSopstellingTHUIS['aantaldoelpunten'];

Dan is het aantaldoelpunten dus wel hetgene waar je op wil controlleren ;)

En het probleem dat je je keeper mist zal waarschijnlijk aan je query liggen.
Ik heb deze niet nagekeken.

Reageren