Solved

while loop in html mail format

Posted on 2016-11-22
5
32 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 10

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 32

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now