Jump to content

Help with mysql_fetch_array function


ameer71

Recommended Posts

please tell me the reason that why mysql_fetch_array does not work inside a function

 

for example the following works well in its current form

 

$sql="SELECT * FROM $tbl_13";

$query=mysql_query($sql);

while($rs=mysql_fetch_array($query)){

$p0 = $rs["pfid"];

$pm = $rs["pm"];

}

 

but when i put it inside a function it gives me an error at

 

function defone() {

$sql="SELECT * FROM $tbl_13";

$query=mysql_query($sql);

while($rs=mysql_fetch_array($query)){

$p0 = $rs["pfid"];

$pm = $rs["pm"];

}

  return $pm;

}

 

the error message is...

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...

Please identify the problem.. i'm an experience programmer in ruby and perl but new in php

 

Link to comment
https://forums.phpfreaks.com/topic/224835-help-with-mysql_fetch_array-function/
Share on other sites

You already have an existing thread for this, where someone replied with the reason why your code does not work.

 

In most programming languages, each function has its own isolated variable scope so that you can freely write any code and define any variables in the function that you need in order to accomplish the goal of that function, without needing to worry about overwriting any of the main program variables. Can you imagine how hard it would be to write a large application if you needed to keep track of all the variables you used to avoid any conflict between the main program and all the function definitions?

 

You need to pass any values, such as your $tbl_13 variable, into the function as a parameter when you call the function.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.