Re: Problem with query

Matijn Woudt <[email protected]>
Newsgroups gmane.comp.php.database
Message-ID <CAC_gtuNjXK_QS6vv8_zcfaLZv12=oc2qVFY3DF8MT7i2ZRJrFw@mail.gmail.com>
On Sun, Jun 23, 2013 at 8:31 PM, Ethan Rosenberg, PhD <
[email protected]> wrote:

> Dear List -
>
> There is an error in my query, and I cannot find it.
>
> This fails:
>
> $_SESSION['Cust_Num'] = $_REQUEST['cnum'];
> $_SESSION['CustNum'] = $_REQUEST['cnum'];
>
> echo "session<br />"; //this has the proper values
> print_r($_SESSION);
>
> $sql10 = "select Balance, Payments, Charges, Date from Charges where
> Cust_Num = $_SESSION[Cust_Num] order by Date";
> echo $sql10; //echos the correct query
> $result10 = mysqli_query($cxn, $sql10);
> var_dump($result1); // this returns NULL
> echo "<center><strong>Current Results</strong></center>";
> echo "<center>";
> echo "<table border='4' cellpadding='5' cellspacing='55' rules='all'
> frame='box'>";
> echo "<tr class='heading'>";
> echo "<th>Balance</th>";
> echo "<th>Payments</th>";
> echo "<th>Charges</th>";
> echo "<th>Date</th>";
> echo "</tr>";
> echo "row1<br />";
>

$row10 is undefined here, so:
$row10 = mysqli_fetch_row($result10); ?

I would suggest using
while (($row1 = mysqli_fetch_row($result1))!= 0 ) { ... }

instead of
do { ... } while (($row1 = mysqli_fetch_row($result1))!= 0 );

This avoids the need of the extra mysqli_fetch_row before the do-while loop.

- Matijn
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.