Jump to content

Recommended Posts

What I have is a scores table. It has a list of every sports match, some are played and some are not.

What I want to do is make a playerlist, for who is playing in the next UNPLAYED sports match who are in teams 1, 2, 3 and 4. (There are 19 teams but I only want to do this for first 4).

Here is my code:

[code]<?
require_once("connection.php");

$sql  = "SELECT home, away, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19` ";
$sql .= "FROM scores ";
$sql .= "WHERE team_id="1", "2", "3", "4" ";
$sql .= "ORDER BY date";
$sql .= "LIMIT 4";

$result = mysql_query($sql);

if(mysql_num_rows($result)!=0) {

while(list($home, $away, $_1, $_2, $_3, $_4, $_5, $_6, $_7, $_8, $_9, $_10, $_11, $_12, $_13, $_14, $_15, $_16, $_17, $_18, $_19 ) = mysql_fetch_row($result)) {
?>
Playerlist for match: <?=$home?> vs <?=$away?>
<br /><br />
<table width="300" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="30"><strong>#</strong></td>
    <td width="270"><strong>Player</strong></td>
  </tr>
  <tr>
    <td>1</td>
    <td><?=$_1?></td>
  </tr>
  <tr>
    <td>2</td>
    <td><?=$_2?></td>
  </tr>
  <tr>
    <td>3</td>
    <td><?=$_3?></td>
  </tr>
  <tr>
    <td>4</td>
    <td><?=$_4?></td>
  </tr>
  <tr>
    <td>5</td>
    <td><?=$_5?></td>
  </tr>
  <tr>
    <td>6</td>
    <td><?=$_6?></td>
  </tr>
  <tr>
    <td>7</td>
    <td><?=$_7?></td>
  </tr>
  <tr>
    <td>8</td>
    <td><?=$_8?></td>
  </tr>
  <tr>
    <td>9</td>
    <td><?=$_9?></td>
  </tr>
  <tr>
    <td>10</td>
    <td><?=$_10?></td>
  </tr>
  <tr>
    <td>11</td>
    <td><?=$_11?></td>
  </tr>
  <tr>
    <td>12</td>
    <td><?=$_12?></td>
  </tr>
  <tr>
    <td>13</td>
    <td><?=$_13?></td>
  </tr>
  <tr>
    <td>14</td>
    <td><?=$_14?></td>
  </tr>
  <tr>
    <td>15</td>
    <td><?=$_15?></td>
  </tr>
  <tr>
    <td>16</td>
    <td><?=$_16?></td>
  </tr>
  <tr>
    <td>17</td>
    <td><?=$_17?></td>
  </tr>
  <tr>
    <td>18</td>
    <td><?=$_18?></td>
  </tr>
  <tr>
    <td>19</td>
    <td><?=$_19?></td>
  </tr>
</table>
<br/><br/>
<?
}
}
?>
[/code]


As you can see the WHERE is probably wrong? I want it to do teams 1, 2, 3 and 4. The other thing is, how do I make it only display the matches with no score? So maybe:

if($score == "") or something? I really need help on what to do here.

The numbers you see 1 to 19 are the players.
Link to comment
https://forums.phpfreaks.com/topic/21384-multiple-tables-help-with-where/
Share on other sites

You need to use [color=red]IN[/color] for your [color=green]WHERE[/color] clause and you can use [color=red]IS NULL[/color] for your scores, assuming the field is null by default.

[code]
<?php
$sql  = "SELECT home, away, `1`, `2`, `3`, `4`, `5`, `6`, `7`, `8`, `9`, `10`, `11`, `12`, `13`, `14`, `15`, `16`, `17`, `18`, `19` ";
$sql .= "FROM scores ";
$sql .= "WHERE team_id IN (1, 2, 3, 4) ";
$sql .= "AND score IS NULL ";
$sql .= "ORDER BY date ";
$sql .= "LIMIT 4";
?>
[/code]

Regards
Huggie
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.