How to handle zero rows found - invalid $output

How to handle zero rows found - invalid $output

PeteBPeteB Posts: 38Questions: 0Answers: 0
edited March 2012 in General
Hi,

I'm afraid I need to request some help once again:

I have a fairly simple table that is populated by PHP/MySQL:

[code] <?php
include('conn.php');

$plyrno = $_GET['playerno'];
$aColumns = array( 'HPplayerID', 'honname', 'HPseasonID' );

$sQuery = "
SELECT SQL_CALC_FOUND_ROWS
HPplayerID,
honname,
HPseasonID
FROM table1 a, table2 b
WHERE a.HPplayerID = $plyrno
AND a.HPhonourID = b.honourID
";

$rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());

while ( $aRow = mysql_fetch_array( $rResult ) )
{
$row = array();
for ( $i=0 ; $i

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Looks like a PHP error to me - your $output variable is only being defined inside the while loop, and if that never runs through then you are json encoding an undefined variable.

    Allan
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    Allan,

    yes, that's what I thought. But I just 'blindly' copied the routine from a previous post and haven't determined how to amend it yet.
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    This seems to work (to a degree):

    [code] $rResult = mysql_query( $sQuery, $gaSql['link'] ) or die(mysql_error());
    $total_results = mysql_num_rows($rResult);

    while ( $aRow = mysql_fetch_array( $rResult ) )
    {
    $row = array();
    for ( $i=0 ; $i
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Just declare $output before you use it:

    [code]
    $output = array( 'aaData' => array() );
    [/code]

    Allan
  • PeteBPeteB Posts: 38Questions: 0Answers: 0
    Allan,

    thanks once again - I now get a nice 'no data available in table' message rather than the row of zeroes I'd created.
This discussion has been closed.