mysql_fetch_array() expects parameter 1 to be resource problem
You are not doing error checking after the call to mysql_query:
$result = mysql_query("SELECT * FROM student WHERE IDNO=".$_GET['id']);
if (!$result) { // add this check.
die('Invalid query: ' . mysql_error());
}
In case mysql_query
fails, it returns false
, a boolean
value. When you pass this to mysql_fetch_array
function (which expects a mysql result object
) we get this error.
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...' but my query is correct
$query = "SELECT * FROM newuser WHERE token='$token'";
$result = mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result)) {
do stuff...
}
If the die
statement is not executed, $result
is OK when you enter the while loop. The problem then is probably that you use $result
for a query inside the loop as well, eventually leading to it being set to false.
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
Your query ($myQuery) is failing and therefore not producing a query resource, but instead producing FALSE.
To reveal what your dynamically generated query looks like and reveal the errors, try this:
$result2 = mysql_query($myQuery) or die($myQuery."<br/><br/>".mysql_error());
The error message will guide you to the solution, which from your comment below is related to using ORDER BY on a field that doesn't exist in the table you're SELECTing from.
Unexpected Warning - mysql_fetch_array() expects parameter 1 to be resource, boolean given
Given that your while
loop "runs once, even though there are 3 results", I'm going to take a shot in the dark and say that you are using $result
in the loop contents by mistake.
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given.
first try to check the data of $q
and after that try with this query:
mysql_query("SELECT * FROM `ajax_demo`
WHERE id = '" . mysql_real_escape_string($q) ."'");
Related Topics
Posting Multidimensional Array with PHP and Curl
Find Common Values in Multiple Arrays with PHP
Magento - Retrieve Products with a Specific Attribute Value
Include Constant in String Without Concatenating
Int((0.1+0.7)*10) = 7 in Several Languages. How to Prevent This
Remove Bom () from Imported .CSV File
Convert Invalid JSON into Valid JSON
Check Whether a Request Is Get or Post
Using JSON_Encode on Objects in PHP (Regardless of Scope)
Accessing Class Properties with Spaces
How to Prevent Pdo from Interpreting a Question Mark as a Placeholder
Laravel Model with Two Primary Keys Update
How to Capture PHP Output into a Variable
PHP Create a Multidimensional Array from an Array with Relational Data
Woocommerce: Assigning an Endpoint to a Custom Template in My Account Pages
How to Use Objects from Other Namespaces and How to Import Namespaces in PHP