Solved

while loop in html mail format

Posted on 2016-11-22
5
92 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 12

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 34

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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This article discusses how to implement server side field validation and display customized error messages to the client.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

630 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