Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

php warning

Links for php scripts

Moderators: macek, egami, gesf

php warning

Postby minotron » Thu Apr 26, 2012 7:13 am

Hi

I have this code:

Code: Select all
$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(mysql_error($db));
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))  //at this line is the warning
{
extract($row);


It writes me this error: "Warning: mysql_fetch_array() expects parameter 1 to be resource, string given in H:\xampp\htdocs\rozpis.php on line 18"
I can't find problem in this code. Do you know what is bad? Thank you for reply.
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby egami » Thu Apr 26, 2012 7:44 am

mysql_error($db)

this should not have any variables..

should be just die ("ERROR: ".mysql_error());
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: php warning

Postby minotron » Thu Apr 26, 2012 7:48 am

I have changed that, but it still writes the same warning.
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby egami » Thu Apr 26, 2012 7:57 am

Code: Select all


$sql 
"SELECT game_id, rival_id, result, h_a, UNIX_TIMESTAMP(datum) AS datum FROM game ORDER BY datum ASC";
$result mysql_query($sql) or die(mysql_error());
$numrow mysql_num_rows($result);
if(
$numrow 0)
  
$count 0;
  while(
$row mysql_fetch_array($result)) { 
    $++
count;
    if (
$count 15) { // This is so we don't fill the page up.. who knows how many rows you have...
      
break;
    }
    echo 
'<pre>'print_r($row); echo '</pre>';
  }
} else { 
  echo 
"QUERY: $sql <br />";
  echo 
"Found $numrow entries..<br />";
  echo 
"Try running the above query in your phpMyAdmin or SQL Manager to see if the query works outright<br/>";
}

 
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: php warning

Postby minotron » Thu Apr 26, 2012 8:14 am

When I run query in phpmyadmin it shows correct values...but when I run it in localhost it shows this message and writes only first row from table...and when I changed it so how you have written it, it showed the same warning...it is very mysterious :) :help:
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby minotron » Thu Apr 26, 2012 8:17 am

and when I try to run:
Code: Select all
echo mysql_num_rows($result)
it writes right value
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby egami » Thu Apr 26, 2012 8:32 am

show me your entire script please.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: php warning

Postby minotron » Thu Apr 26, 2012 8:37 am

Code: Select all
<?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';
?>
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby egami » Thu Apr 26, 2012 9:41 am

first things first..
change the first mysql_fetch_array to mysql_fetch_assoc

You have two SQL calls, and you're trying to extract() names that don't exist.

So change the first one to assoc, and not array, and then try to run it again.. I want to see if the error is calling on the second SQL and not the first.
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: php warning

Postby minotron » Thu Apr 26, 2012 10:30 am

When I changed the first mysql_fetch_array($result) to mysql_fetch_assoc($result) it had written warning about mysql_fetch_assoc($result) so the problem is in the first one...
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby egami » Thu Apr 26, 2012 10:50 am

$sql = "SELECT game_id, rival_id, result, h_a, UNIX_TIMESTAMP(datum) AS datum FROM game ORDER BY datum ASC";

change that to
$sql = "SELECT * FROM game ORDER BY datum ASC";
User avatar
egami
php-forum GURU
php-forum GURU
 
Posts: 2197
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: php warning

Postby minotron » Thu Apr 26, 2012 11:49 am

It writes the same error and now writes else problem with date: Notice: A non well formed numeric value encountered in H:\xampp\htdocs\rozpis.php on line 24 ...it's this line:
Code: Select all
echo '<td>' .date("j. F Y", $datum). '</td>';
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am

Re: php warning

Postby minotron » Fri Apr 27, 2012 6:40 am

I have solved it so, that I deleted: extract($row) and now it goes, thank you for your help
minotron
New php-forum User
New php-forum User
 
Posts: 8
Joined: Thu Apr 26, 2012 7:08 am


Return to PHP Scripts

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.