Quantcast
Channel: DaniWeb Solved Topics
Viewing all articles
Browse latest Browse all 564

PHP function call renders blank screen

$
0
0

Using PHP / MySQL

This is a sort of long explanation, but trying to provide all the information the first time.
Hopefully someone can tell me what Im missing or doing wrong, without too much criticism.

I am trying to create a FUNCTION that I can use to retrieve a list of the most recent friends that a member has referred to their website that have subsequently registered as a client(member)

Im doing it in a function because this information will be displayed in a block on their back office dashboard, along with other data blocks on the same page with other lists in them, and I want to provide them a link/icon to click on to Refresh the listing of the information in that block only, without needing to reload the entire page...
Hopefully I can do that with a simple call to the function... guess I'll find out.

Hope that makes sense.

I intend to call the function with function call: recent_friends($mem_id, $fmax, $ord_by, $dir)
Where the $mem_id is the logged in member, $fmax is the maximum number of entries to display, $ord_by is naturally the column to order by, and $dir is either Ascending or Decending

DB Table called members
(list of relevant fields)
mem_id / user / email / status / fname / lname / mem_status / join_date / ref_id

Function call in script:
$friends = recent_friends($_SESSION['mem_id'], 10, 'join_date', 'D');

// ***********************************************************************
//  retrieve list of friends referred by member to client website
//  call by setting variable = recent_friends(mem_id, max, ord_by, dir)

  function recent_friends($mem_id, $fmax, $ord_by, $dir)
  {
    if ($dir == 'A'){ $list_dir = 'ASC'; }else{ $list_dir = 'DESC'; }

    $sql_data = "
    SELECT mem_id, user, fname, lname, mem_status, join_date
    FROM members
    WHERE ref_id = '".$mem_id."'
    ORDER BY ".$ord_by." ".$list_dir;

    if ($fmax != 'A'){    // if limit defined - append to query
      $sql_data .= " LIMIT ".$fmax; 
    }

  $result = mysqli_query($connection,$sql_data);

  $friends = array();

    while($row = mysql_fetch_assoc($result)){
      $friends[] = $row;
    }

    return $friends;
  }//end function
When the function is called I get a blank screen

I dont know if the function call is malformed or if the function itself has an issue causing it.

Also, tried it with the database connection call inside the function and without it... No change.

include "tm_connect.php"; // connects to database

And the page that should display this information in a table code section looks like this

                        <tbody>
<?php
     foreach ($friends as $row)
        {
?>
                            <tr>


                                <td>
                                    <span class="font-w600"><?php echo $row['user'];?></span>
                                </td>
                                <td class="d-none d-sm-table-cell text-center">
                                    <?php echo $row['fname']." ".$row['lname'];?>
                                </td>
                                <td class="font-w600">
                                    <?php echo $row['mem_status'];?>
                                </td>
                                <td class="d-none d-sm-table-cell text-center">
                                    <?php echo $row['join_date'];?>
                                </td>
 <?php
        }
?>
                           </tr>
                        </tbody>

Viewing all articles
Browse latest Browse all 564

Trending Articles