mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource

后端 未结 30 3254
鱼传尺愫
鱼传尺愫 2020-11-21 06:25

I am trying to select data from a MySQL table, but I get one of the following error messages:

mysql_fetch_array() expects parameter 1 to be resource,

30条回答
  •  遥遥无期
    2020-11-21 06:57

    First, check your connection to the database. Is it connected successfully or not?

    If it's done, then after that I have written this code, and it works well:

    if (isset($_GET['q1mrks']) && isset($_GET['marks']) && isset($_GET['qt1'])) {
        $Q1mrks = $_GET['q1mrks'];
        $marks = $_GET['marks'];
        $qt1 = $_GET['qt1'];
    
        $qtype_qry = mysql_query("
            SELECT *
            FROM s_questiontypes
            WHERE quetype_id = '$qt1'
        ");
        $row = mysql_fetch_assoc($qtype_qry);
        $qcode = $row['quetype_code'];
    
        $sq_qry = "
            SELECT *
            FROM s_question
            WHERE quetype_code = '$qcode'
            ORDER BY RAND() LIMIT $Q1mrks
        ";
        $sq_qry = mysql_query("
            SELECT *
            FROM s_question
            WHERE quetype_code = '$qcode'
            LIMIT $Q1mrks
        ");
        while ($qrow = mysql_fetch_array($sq_qry)) {
            $qm = $qrow['marks'] . "
    "; $total += $qm . "
    "; } echo $total . "/" . $marks; }

提交回复
热议问题