English 中文(简体)
我的SQL询问——仍然有回归错误的我的sql_fetch_array[复制]。
原标题:mySQL query - still returns error mysql_fetch_array [duplicate]
  • 时间:2012-01-11 11:42:00
  •  标签:
  • php
  • mysql
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
mySQL query multiple - returns error mysql_fetch_array

我有2个数据库表(簿记系统),其结构如下:

季度:

id_quarto.
tipo_quarto.
vista_quarto.

保留:

id_reserva.
n_cliente.
id_quarto.
check_in.
check_out.

我要问一下,是否将原封地(从中转)归还(从中转)原封地(从中取出)原封地,这样就写了以下的询问(也从前一种形式收集信息):

NOTE: 目前,我没有考虑支票_in和支票_outdate_index....... 这只是一种考验,因此,我会增加检查条件,但如果任何人对这些条件有某种想法,会感激。

// Connect to database server
mysql_connect("localhost", "root") or die (mysql_error ());

// Select database
mysql_select_db("teste") or die(mysql_error());

// Get data from the database

    $strSQL = "SELECT id_quarto,tipo_quarto,vista_quarto ".
              " FROM quartos,reservas ".
              " WHERE quartos.id_quarto!=reservas.id_quarto ".
              " AND quartos.tipo_quarto= ". mysql_real_escape_string($_POST[ tipo_quarto ]) ."  ".
              " AND quartos.vista_quarto= ". mysql_real_escape_string($_POST[ vista_quarto ]) ." ";
$rs = mysql_query($strSQL);


    // Loop the recordset $rs
        // Each row will be made into an array ($row) using mysql_fetch_array
        while($row = mysql_fetch_array($rs)) {

    ?>
    <table border="1">
        <tr align="left">
        <td width="75"><?php echo $row[ id_quarto ]; ?></td>
        <td width="75"><?php echo $row[ vista_quarto ]; ?></td>
        <td width="75"><?php echo $row[ tipo_quarto ]; ?></td></tr>
      </table>
     <?php 
     }

       // Close the database connection
    //  mysql_close(); ?>

但是,当我这样做时,我回去了X线上的错误,而X线就是一线。 记录显示,“Msql_fetch_array()预计参数1是资源,boolean”。

为什么这样做,以及我能做些什么来防止这种情况? 如何撰写正确的法典?

此外,我还希望把结果作为选择(List/Menu)的项目,以便用户只能选择有效结果。 如何将记录结果纳入这一特点的想法?

问题回答

阁下

$rs=mysql_query($strSQL)

提早

// Loop the recordset $rs

严格地说:

if ($rs=mysql_query($strSQL)) {

// Proceed with while loop

} else echo mysql_error();

问题是否会产生错误?





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签