Detta tar upp mycket tid. Jag får dock inte ordning på detta.
Med test.php radas matcherna så här:
2007-01-03 15:00
2. AIK-Häcken BK
3. IFK Göteborg-Malmö FF
4. Halmstad BK-Helsingborg IF
5. Öster IF-Gävle IF
"submitknapp"
2007-01-04 13:00
6. Trelleborg-Norrköping
"submitknapp"
När jag trycker på submitknappen vill jag till spel.php som endast skall visa matcherna med samma date eller match_id som jag sätter i sessionen i test.php.
Nu får jag felmeddelande
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in C:\wamp\www\test.php on line 10
Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\test.php:10) in C:\wamp\www\test.php on line 12
Vad gör jag för fel?
Mina filer
test.php
<?php
session_start(); // Alltid överst på sidan
include 'conn.php';
if (isset($_POST['post'])){
// Sätt sessionen med unikt index
$_SESSION['sess_match_id'] = mysql_result($result, 0, 'match_id');
$_SESSION['sess_date'] = $day;
header("Location: spel.php");
exit;
}
$sql = "SELECT DATE_FORMAT(date,'%Y-%m-%d %H:%i') as date, matcher, match_id
FROM allsv2007 WHERE date > CURRENT_TIMESTAMP()
ORDER BY date ASC";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$date[$row['date']][] = array($row['match_id'], $row['matcher']);
}
if (isset($date) && !empty($date)) {
echo '<table>';
foreach ($date as $day => $value){
echo '<tr>';
echo '<td></td>';
echo '<td>' . '<b>' . $day. '</b>' . '</td>';
echo '</tr>';
foreach ($value as $game)
{
echo '<tr>';
echo '<td align ="right">'. $game[0].'.</td>';
echo '<td>'. $game[1].'</td>';
echo '</tr>';
}
echo '<tr>';
echo '<td></td>';
echo '<td>
<form action="test.php" method="post">
<input type="submit" name="post" value="Spela">
</form>
</td>';
echo '</tr>';
}
echo '</table>';
}else{
echo 'inga matcher i databasen';
}
?>
spel.php
<?php
session_start(); // Alltid överst på sidan
include "conn.php"; // Databasanslutningen
// Kolla om inloggad = sessionen satt
if (!isset($_SESSION['sess_date'])){
header("Location: test.php");
exit;
}
$sql = "SELECT DATE_FORMAT(date,'%Y-%m-%d %H:%i') as date, matcher, match_id
FROM allsv2007 WHERE date > CURRENT_TIMESTAMP() AND date = ' {$_SESSION['sess_date']} ' ORDER BY date ASC" or die(mysql_error());
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
$date[$row['date']][] = array($row['match_id'], $row['matcher']);
}
if (isset($date) && !empty($date)) {
echo '<table>';
foreach ($date as $day => $value){
echo '<tr>';
echo '<td></td>';
echo '<td>' . '<b>' . $day. '</b>' . '</td>';
echo '</tr>';
foreach ($value as $game)
{
echo '<tr>';
echo '<td align ="right">'. $game[0].'.</td>';
echo '<td>'. $game[1].'</td>';
echo '</tr>';
}
echo '<tr>';
echo '<td></td>';
echo '<td></td>';
echo '</tr>';
}
echo '</table>';
}else{
echo 'inga matcher i databasen';
}
?>