Status
Not open for further replies.

GoPantheoN

Active Member
908
2009
19
0
Consider there is the following table.

384165.jpg


Now I want to query only the rows whose value is 1.

I use the following code

Code:
$sql="SELCET  name, reg, branch, year from i11 where sf='1'";
$result=mysql_query($sql);
while ($row=mysql_fetch_array($result))
but I got the following warning

Code:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in \xampp\htdocs\reg\events.php on line 19


Kindly give information about the correct query.

Thank you.
 
5 comments
You can check with the following if your mysql_query is being executed properly:


Error: you have SELCET instead SELECT
Code:
$sql="SELCET  name, reg, branch, year from i11 where sf='1'";

Correct query:
Code:
$sql = "SELECT  name, reg, branch, year FROM i11 WHERE sf='1'; ";
 
Code:
$get=mysql_query("Select * from i11 where sf='1'");
while($result = mysql_fetch_assoc($get))
you can use field names instead of *
 
@deAthbLisS

Using * in a query is great to get all the fields, but MySQL tends to have better queries when you specify which fields do you need to get from the MySQL table.

If a MySQL table has 30 fields, and you need only 5 for your query, then selecting other 25 would be a huge overkill, as it would take more tie for MySQL to execute the query.
Specifying table fields that you need to select is part of MySQL best practice programming and it's good to stick to it even if you have 3 fields in you table.

Optimize where you can.
 
Status
Not open for further replies.
Back
Top