Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Row 1 of table not being printed.........

Status
Not open for further replies.

34534534534555

IS-IT--Management
Jan 8, 2003
240
0
0
GB
Hello,

I have the following script to print a mysql table info to a file. It prints the column titles, and then row2, row3, row4. BUT, not row1? I presume i have a counter wrong or something.... but i can't see it!

Code:
$condition = mysql_num_fields($result);

for ($i = 0; $i < $condition; $i++)
	
	{ 
	echo mysql_field_name($result, $i) . "\t"; 
	}
	
	print ("\t");
	print ("\n");
	
while($row = mysql_fetch_array($result)) 

	{
	for($j = 0; $j < $condition; $j++)
		{
		while ($myrow = mysql_fetch_array($result)) 
			{
			$name = $myrow["name"];
			$mobilenumber = $myrow["mobilenumber"];
		
			echo $name; 
			print ("\t");
			echo $mobilenumber;
			print ("\n");
			}
		}
	}

print "\n";

Additionally, if anyone knows a good mysql -> xls / doc tutorial, please point!

Specifically, how do i format the xls file? Bold and centre the column titles and autowidth the columns? And, my file downloads automatically when clicking on the hyperlink, how do i tell the computer to open that file once downloaded?

Thanks in advance.
 
You have two nested while loops. The first loop retrieves the first row. The second while then calls the second row, the first is lost already.

I don't really understand what you are trying to do. What is the for loop 'for' (no pun inteded)?

A simple loop like this should suffice:
Code:
while ($row = mysql_fetch_assoc($result)){
   print $row['name']."\t".$row['mobilenumber']."\n";
}
 
Hi DRJ478,

Thank you so much for your help, your advice is invaluable.

I was trying to do exactly what your code does! Mine is very messy as i'm not 100% sure what i am doing, just bumping along! The code is to print a two column table to an .xls file -which now works!

Do you know how to tell Excel to stop chopping off the 0's!?


| Feedback is always appreciated as this will help to further our knowledge as well |
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top