Solved

while loop in html mail format

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

740 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