mysterious warning in PHP

Discussion in 'PHP' started by minotron, Apr 27, 2012.

  1. #1
    Hi,
    I have this code:
    
    <?php
    include 'connect.inc.php';
    include 'header.inc.php';
    
    
    
    $mesiace  = array("Január", "Február", "Marec", "Apríl", "Máj", "Jún", "Júl",  "August", "September", "Október", "November", "December");
    
    echo '<div id="rozpis">';
    $sql = "SELECT game_id, rival_id, result, h_a, UNIX_TIMESTAMP(datum) AS datum FROM game ORDER BY datum ASC";
    $result = mysql_query($sql, $db) or die("ERROR: ".mysql_error());
    if(mysql_num_rows($result) > 0)
    {
    echo '<table>';
    echo   '<tr><td>Dátum</td><td>Domáci</td><td>Hostia</td><td>Výsledok</td></tr>';
    while($row = mysql_fetch_array($result))
    {
    extract($row);
    $prikaz = 'SELECT rival_id, name FROM rival WHERE rival_id = '. $rival_id;
    $vystup = mysql_query($prikaz, $db) or die(mysql_error($db));
    $rival = mysql_fetch_array($vystup);
    echo '<tr>';
    echo '<td>' .date("j. F Y", $datum). '</td>';
    if ($h_a == 1)
    {
    echo '<td> Capitals </td>';
    echo '<td>' .$rival['name']. '</td>';
    }
    else
    {
    echo '<td>' .$rival['name']. '</td>';
    echo '<td> Capitals </td>';
    }
    echo '<td><a href="zapas.php?zapas='. $game_id.'">' .$result. '</td>';
    echo '</tr>';
    }
    echo '</table>';
    }
    else
    echo 'No matches';
    
    echo '</div>';
    
    include 'zahlavie.php';
    ?>
    
    PHP:
    When I run this script it writes this warning: Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in H:\xampp\htdocs\rozpis.php on line 16 I really dont't know where is problem... In the table I have three rows, but it writes only the first one and then this message. When I run $query in phpMyAdmin it runs corecctly or when I use: echo mysql_num_rows($result) it goes corecctly also.
    I will be grateful, if you find the problem...
     
    minotron, Apr 27, 2012 IP
  2. GMF

    GMF Well-Known Member

    Messages:
    855
    Likes Received:
    113
    Best Answers:
    19
    Trophy Points:
    145
    #2
    I have not much time so just a suggestion:

    Check your $result and see if you get what you desire. Also, check this

    http://stackoverflow.com/questions/5473981/warning-mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-i
    Code (markup):

    hope it helps
     
    GMF, Apr 27, 2012 IP
  3. minotron

    minotron Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I checked $result in: if(mysql_num_rows($result)) and it goes corectly...it also writes first row of the table but more not...
     
    minotron, Apr 27, 2012 IP
  4. Jeehan

    Jeehan Well-Known Member

    Messages:
    1,578
    Likes Received:
    31
    Best Answers:
    1
    Trophy Points:
    115
    #4
    Im not anywhere close to good programmer but, that could be problem related to your xampp installation ?
     
    Jeehan, Apr 27, 2012 IP
  5. minotron

    minotron Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I don't think, that there is a problem in xampp installation. I have used this type of script lots of times before and it was OK, but I don't understand where is problem now. I tried almost everything to make it right, but still doesnt go.
     
    minotron, Apr 27, 2012 IP
  6. minotron

    minotron Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    I deleted extract($row) and now it goes corectly :)
     
    minotron, Apr 27, 2012 IP