malikah Posted April 9, 2007 Share Posted April 9, 2007 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 More sharing options...
MadTechie Posted April 9, 2007 Share Posted April 9, 2007 would probably work is you included the $nat["cc"] & $dtn["cc"] that its needs Link to comment https://forums.phpfreaks.com/topic/46247-solved-query-inside-a-function/#findComment-224842 Share on other sites More sharing options...
malikah Posted April 9, 2007 Author Share Posted April 9, 2007 would probably work is you included the $nat["cc"] & $dtn["cc"] that its needs I'm not quite sure what you mean.. Link to comment https://forums.phpfreaks.com/topic/46247-solved-query-inside-a-function/#findComment-224843 Share on other sites More sharing options...
MadTechie Posted April 9, 2007 Share Posted April 9, 2007 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"]); ?> Link to comment https://forums.phpfreaks.com/topic/46247-solved-query-inside-a-function/#findComment-224848 Share on other sites More sharing options...
malikah Posted April 9, 2007 Author Share Posted April 9, 2007 Worked perfectly - and cleaned up my code as a bonus! Cheers. Link to comment https://forums.phpfreaks.com/topic/46247-solved-query-inside-a-function/#findComment-224850 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.