Peta2010 Ответов: 3

Предупреждение: mysqli_num_rows() ожидает, что параметр 1 будет mysqli_result, логическое значение задано в


Привет

Я пытаюсь запустить свою поисковую форму и получаю эту ошибку на странице результатов

Предупреждение: mysqli_num_rows() ожидает, что параметр 1 будет mysqli_result, логическое значение задано в /Applications/XAMPP/xamppfiles/htdocs/m/results.php на линии 84
Результаты поиска не найдены...пожалуйста, выполните поиск еще раз

Мой код для страницы результатов :

<?php
// Check that the form has been submitted
if ($_POST) {

    // Store the form data in variables

    $form_series_name = $_POST['series_name'];
    $form_card_player = $_POST['card_player'];
    $form_card_condition = $_POST['card_condition'];
    //$form_card_price = $_POST['card_price'];


    // Check if the radio button data exists
     if (array_key_exists('card_condition', $_POST))
     {
     $form_card_condition = $_POST['card_condition'];
      }
      else
      {
        $form_card_condition = "";
            }

    // Trim any trailing and leading spaces from the form data
    $form_series_name = trim($form_series_name);
    $form_card_player = trim($form_card_player);
    $form_card_condition = trim($form_card_condition);



    // Open a connection to the database
    $link = mysqli_connect(----------my values-------);

    // Define a query that retrieves all fields names and id
    $query = "SELECT cards.card_id, series.series_name, cards.card_player,cards.card_condition
    FROM cards, series
    WHERE cards.cards_id = series.series_id";


    // Restrict the SQL query with an AND clause if a
    // series id has been supplied
    if ($form_series_id != 0)
     { $query .= "AND series.series_id = $form_series_id "; }

    // if player name  has been supplied
    if ($form_card_player != "")
    {
        $query .= " AND cards.card_player= '$form_card_player'";
    }

    // Restrict the SQL query with an AND clause if a contract  status has been supplied
    if ($form_card_condition != "")
    {
         $query .= "AND cards.card_condition = $form_card_condition ";
     }



    //this will check the value put by the user in the lowest price  box by the user
    //if ($form_lowest_price != "")
    //{
        //$query .= " AND card_price >= $form_lowest_price";
    //}

    //this will check the value put by the user in the highest price  box by the user
    //if ($form_highest_price != "")
    //{
        //$query .= " AND card_price <= $form_highest_price"; // this will show the query
    //}

    // Run the query and store the result
    $result = mysqli_query($link, $query);

    $number = mysqli_num_rows($result);

    //echo $query;

    // this will show the whole tablle record from database if the user not select and type anything on query page
    if ($number == 0)
    {
        echo "No search results found...please search again";
    }
    else
    {

    // this contain the header information in the cell of the table
        echo <<<END
        <Table  width='60%' border="1">
         <TR>
            <TH>Card Id</TH>
            <TH>Series</TH>
            <TH>Player </TH>
            <TH>Condition</TH>
            //<TH>Price</TH>

         </TR>
END;
    // Assign each record in the result to an array
    while ($row = mysqli_fetch_array($result))
    {
        // Assign each array element to a variable
        $card_id = $row['card_id'];
        $series_name = $row['series_name'];
        $card_player = $row['card_player'];
        $card_condition = $row['card_condition'];


       if ($card_condition == 1)
        {
            Echo "<TD>Mint</TD>";
        }
        elseif ($card_condition == 2)
        {
            Echo "<TD>Good</TD>";
        }
        elseif ($card_condition == 3)
        {
            Echo "<TD>Very Good</TD>";
        }
        //$card_price = $row['card_price'];


    // this will show  data from database in the table format what we require in assignment
        Echo "<TR >";

        Echo "<TD>$card_id_id</TD>";
        Echo "<TD>$series_name</TD>";
        Echo "<TD>$card_player</TD>";
        Echo "<TD>$card_condition</TD>";

         "</TR>";

    }
    Echo "</TABLE>";
}

// Close the connection to the database
mysqli_close($link);

}

?>


[edit]добавить правильный тег-johny[/edit]

3 Ответов

Рейтинг:
8

Peta2010

Я использовал неправильный SQL-запрос.

// Define a query that retrieves all fields names and id
    $query = "SELECT cards.card_id, series.series_name, cards.card_player,cards.card_condition
    FROM cards, series
    WHERE cards.cards_id = series.cards_id ";



Спасибо за вашу помощь, ребята.


Рейтинг:
1

CPallini

Вы должны проверить результат (то есть $result) от mysqli_query прежде чем передать его кому-то другому. mysqli_num_rows, см. документация [^].


Рейтинг:
1

Mohibur Rashid

вы не выбрали базу данных. кроме того, проверьте res, чтобы убедиться, что он работает правильно, если нет, то используйте функцию mysql_error, чтобы получить сообщение об ошибке