422,946 Members | 1,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 422,946 IT Pros & Developers. It's quick & easy.

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

P: 2
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.php") which is included in most pages with
Expand|Select|Wrap|Line Numbers
  1. include("functies.php");
In it there's a function called "songschrijver" which in turn uses two other functions ("herschiknaam" and "herschiknaam2") which are defined in the same "functies.php" page.

This is the code for "songschrijver":
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. function songschrijver($songid){
  3.     $resultaat = mysqli_query($con, "SELECT Auteur_ID, Uitvoerder FROM songs_met_auteurs, uitvoerders_zonder_instr
  4.      WHERE Auteur_ID = uitvoerders_zonder_instr.ID 
  5.      AND Song_ID =" . $songid . "
  6.      ORDER BY Uitvoerder");
  7.      $rij = mysqli_fetch_array($resultaat);
  8.  
  9.      if (mysqli_num_rows($resultaat) > 1){
  10.         if (mysqli_num_rows($resultaat) == 2){ ?>
  11.             <a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
  12.             <?php herschiknaam2($rij['Uitvoerder']); ?></a>
  13.             <?php $rij = mysqli_fetch_array($resultaat);
  14.             print " & "; ?>
  15.             <a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
  16.             <?php herschiknaam2($rij['Uitvoerder']); ?></a>
  17.             <?php
  18.         }
  19.         else{ ?>
  20.             <a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
  21.             <?php herschiknaam2($rij['Uitvoerder']); ?></a>
  22.                 <?php $rij = mysqli_fetch_array($resultaat);
  23.                 while ($rij){
  24.                     print ", "; ?>
  25.                     <a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
  26.                     <?php herschiknaam2($rij['Uitvoerder']); ?></a>
  27.                 <?php $rij = mysqli_fetch_array($resultaat);
  28.                 }
  29.             }
  30.     }
  31.     else{ ?>
  32.         <a href="resultaten_per_auteur.php?nummer= <?php echo $rij['Auteur_ID']; ?>">
  33.             <?php herschiknaam($rij['Uitvoerder']); ?></a><?php
  34.     }
  35. }
  36. ?>
It is used to display the names of songwriters in a cd track list. As for the other functions, "herschiknaam" turns "Lennon, John" into "John Lennon" and "herschiknaam2" turns the same into "Lennon". "songschrijver" 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_array, 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.
Sep 4 '14 #1

✓ answered by guy13

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

Share this Question
Share on Google+
1 Reply


P: 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.
Sep 4 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.