Solved

while loop in html mail format

Posted on 2016-11-22
5
71 Views
Last Modified: 2016-11-22
i want my record in loop but when i use while loop it fetch 5 records but in my db 6 records. and i want number in list (like 1 ,2...) when i use $i= 1; and $i++ code show error. i don't fine where i wrong.
$i =1;
		while($invoicedata = mysql_fetch_array($invoicesql)){
			echo "<pre>";
			print_r($invoicedata);
		$htmlContent .= '<tr>
			<td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;">1</td>
			<td style="text-align:center; border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 60%;" >'.$invoicedata['item_name'].'</td>
			<td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;text-align:right;">'.$invoicedata['item_price'].'</td>
			
		</tr>';
		$i++;
		}

Open in new window

0
Comment
Question by:Amita Singh
  • 3
5 Comments
 
LVL 11

Expert Comment

by:Ganesh Kumar A
ID: 41897156
May be the comment added will help:

$i =1;
            while($invoicedata = mysql_fetch_array($invoicesql)){
                  echo "<pre>";

  echo "<tr><td>".($pre['item_name','item_price'])."</td></tr>";
}
                  print_r($invoicedata);
            $htmlContent .= '<tr>
                  <td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;">1</td>
                  <td style="text-align:center; border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 60%;" >'.$invoicedata['item_name'].'</td>
                  <td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;text-align:right;">'.$invoicedata['item_price'].'</td>
                  
            </tr>';
            $i++;
            }
0
 
LVL 2

Author Comment

by:Amita Singh
ID: 41897165
Thanx for Reply,

its not work. my code is.
$i =1;
		while($invoicedata = mysql_fetch_array($invoicesql)){
			
		$htmlContent .= '<tr>
			<td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;">1</td>
			<td style="text-align:center; border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 60%;" >'.$invoicedata['item_name'].'</td>
			<td style="border: 1px solid #ccc; line-height: 22px; padding: 2px; width: 20%;text-align:right;">'.$invoicedata['item_price'].'</td>
			
		</tr>';
		$i++;
		}

Open in new window

0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 41897201
First of all: When you'll get errors, post them. It's hard to guess otherwise.

Then mysql_fetch_array is deprecated and should not be longer used.

To check the number of rows in your result use

$num_rows = mysql_num_rows($invoicesql);
print_r($num_rows);

Open in new window


cause the basic while loop looks fine.
0
 
LVL 2

Author Comment

by:Amita Singh
ID: 41897248
thank you Stefan,
i found my error. its work now perfect.
0
 
LVL 2

Author Closing Comment

by:Amita Singh
ID: 41897251
Thank you both of you for helping me.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Viewers will learn how the fundamental information of how to create a table.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question