Jump to content

[SOLVED] query inside a function..


malikah

Recommended Posts

Hi, the following query works perfectly on its own, but when I put it inside a function as shown, it doesn't do anything.. (Just to save you some thinking - the code inside the function is perfect.. It's the function itself that has issues..or it could be me..)

 

function bbb(){
$query = "SELECT typename FROM type, ppselection WHERE nat = '".$nat["cc"]."' AND dtn = '".$dtn["cc"]."' AND type.typecode = ppselection.tpe";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)):
print "".$row["typename"]."<br>";
endwhile;
}
bbb();

 

Any ideas??

 

 

Link to comment
https://forums.phpfreaks.com/topic/46247-solved-query-inside-a-function/
Share on other sites

ok see this line

 

$query = "SELECT typename FROM type, ppselection WHERE nat = '".$nat["cc"]."' AND dtn = '".$dtn["cc"]."' AND type.typecode = ppselection.tpe";

 

it requires $nat & $dtn that are both arrays, neither of these are set in the function, thus they have no value, in the main script your probaly find they are set..

 

try this instead

 

<?php

function bbb($nat, $dtn){
$query = "SELECT typename FROM type, ppselection WHERE nat = $nat AND dtn = $dtn AND type.typecode = ppselection.tpe";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)):
print "".$row["typename"]."<br>";
endwhile;
}
bbb($nat["cc"], $dtn["cc"]);

?>

 

 

 

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.