Nick20 Posted November 20, 2011 Share Posted November 20, 2011 Hiya, Does anyone have any idea why this works fine: $heading = 1; $q = "SELECT * FROM btc_links WHERE heading = $heading";$r = @mysqli_query($dbc, $q);echo '<br/><p><ul>';while ($row = mysqli_fetch_array($r, MYSQLI_NUM)){echo '<li><a href="'.$row[2].'" target="blank">'.$row[3].'</a></li>';}echo '</ul></p><br/>'; YET... When I try to implement the same code with a function, I get no returns: function get_link($heading){$q = "SELECT * FROM btc_links WHERE heading = $heading";$r = mysqli_query($dbc, $q);echo '<br/><p><ul>';while ($row = mysqli_fetch_array($r, MYSQLI_NUM)){ echo '<li><a href="'.$row[2].'" target="blank">'.$row[3].'</a></li>';}echo '</ul></p><br/>'; }// end of function $heading = 1; get_link($heading); Hope someone can help, I've been trying to get it to work now for 3 hours!! grr!!! p.s. very excited to be getting Larry's advanced php book through the post tomorrow!! Nick Link to comment Share on other sites More sharing options...
Craig-UK Posted November 21, 2011 Share Posted November 21, 2011 I am not sure if it's relevant but I notice the @ is missing in front of "mysqli_query($dbc, $q);" in your function version. Link to comment Share on other sites More sharing options...
Nick20 Posted November 21, 2011 Author Share Posted November 21, 2011 Thanks for the reply Craig, I'm pretty sure that shouldn't matter... I believe the @ just suppresses error messages which is I think why I left it off to see it it would help get to the bottom of things! Link to comment Share on other sites More sharing options...
Larry Posted November 21, 2011 Share Posted November 21, 2011 The function needs access to the $dbc variable which represents the database connection. Thanks for the continued interest in my books! Link to comment Share on other sites More sharing options...
Nick20 Posted November 21, 2011 Author Share Posted November 21, 2011 Ah! It seems obvious now! Thanks very much indeed! Link to comment Share on other sites More sharing options...
Recommended Posts