Calling a function inside another function doesn't seem to work anymore with mysqli

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guy13
    New Member
    • Dec 2013
    • 2

    #1

    Calling a function inside another function doesn't seem to work anymore with mysqli

    Hi all,

    Need enlightenment about the following:
    I'm trying to adapt my php pages to mysqli. Everything seems to work after a few minor changes except a number of functions (as far as I can tell it's the ones where a function is called inside another function or where the same function is called again at the end of itself: I'll stick to the first problem for now).

    The setup is this: I have a separate php page with a bunch of functions (called "functies.p hp") which is included in most pages with
    Code:
    include("functies.php");
    In it there's a function called "songschrij ver" which in turn uses two other functions ("herschikna am" and "herschiknaam2" ) which are defined in the same "functies.p hp" page.

    This is the code for "songschrijver" :
    Code:
    <?php
    function songschrijver($songid){
    	$resultaat = mysqli_query($con, "SELECT Auteur_ID, Uitvoerder FROM songs_met_auteurs, uitvoerders_zonder_instr
    	 WHERE Auteur_ID = uitvoerders_zonder_instr.ID 
    	 AND Song_ID =" . $songid . "
    	 ORDER BY Uitvoerder");
    	 $rij = mysqli_fetch_array($resultaat);
    	 
    	 if (mysqli_num_rows($resultaat) > 1){
    		if (mysqli_num_rows($resultaat) == 2){ ?>
    			<a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
    			<?php herschiknaam2($rij['Uitvoerder']); ?></a>
    			<?php $rij = mysqli_fetch_array($resultaat);
    			print " & "; ?>
    			<a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
    			<?php herschiknaam2($rij['Uitvoerder']); ?></a>
    			<?php
    		}
    		else{ ?>
    			<a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
    			<?php herschiknaam2($rij['Uitvoerder']); ?></a>
    				<?php $rij = mysqli_fetch_array($resultaat);
    				while ($rij){
    					print ", "; ?>
    					<a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
    					<?php herschiknaam2($rij['Uitvoerder']); ?></a>
    				<?php $rij = mysqli_fetch_array($resultaat);
    				}
    			}
    	}
    	else{ ?>
    		<a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
    			<?php herschiknaam($rij['Uitvoerder']); ?></a><?php
    	}
    }
    ?>
    It is used to display the names of songwriters in a cd track list. As for the other functions, "herschikna am" turns "Lennon, John" into "John Lennon" and "herschikna am2" turns the same into "Lennon". "songschrij ver" checks how many authors a song has and then uses the other functions to display e.g. "John Lennon", "Lennon & McCartney" or "Harrison, Lennon, McCartney, Starr".

    This worked perfectly with the mysql formulae (e.g. mysql_query, mysql_fetch_arr ay, etc.) but doesn't anymore with mysqli (mysqli_query, etc.). When before it would display "Yesterday (Lennon & McCartney)", the same page now says "Yesterday ()". Is this something to do with calling functions inside functions?

    Any help would be much appreciated.
  • guy13
    New Member
    • Dec 2013
    • 2

    #2
    Got the solution via different channel: forgot to define $con in the function. Doing this completely solved this and the other problem I mentioned.

    Comment

    Working...