Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php

	$host="localhost"; // Host name 
	$username=""; // Mysql username 
	$password=""; // Mysql password 
	$db_name="test1"; // Database name

	// Connect to server and select databse.
	$ligaBD=mysqli_connect("$host", "root", "")or die("cannot connect");
	$escolheBD=mysqli_select_db($ligaBD,"$db_name")or die("cannot select DB");


		$table_name='names';

		# Primeiro Comando
		$qColumnNames = mysqli_query($ligaBD, 'SHOW COLUMNS FROM '.$table_name.''); 
		$numColumns = mysqli_num_rows($qColumnNames);
		# Table Start
		echo '<table border="1">';
			# Table Head
			echo '<thead>
					<tr>';
			for ($i=0; $i<$numColumns; $i++) { 
			 	$colname = mysqli_fetch_row($qColumnNames);
			    echo '<th>'.$colname[0].'</th>';
			}
			echo '	</tr>
				</thead>';
			# Table Body
			echo '<tbody>';
			# Segundo Comando
			$sql2='SELECT * FROM '.$table_name.'';
			$result2=mysqli_query($ligaBD, $sql2); 
			$nlinhas2=mysqli_num_rows($result2);
			for ($i=0; $i<$nlinhas2; $i++) { 
				$dados2=mysqli_fetch_array($result2);
				echo '<tr>';
				foreach ($dados2 as $d2) { 
					echo '<td>'.$d2.'</td>';
				}
				echo '</tr>';
			}
			echo '</tbody>
			</table>
			<br>';		
 ?>



I've Tried this but the result was that:

HTML
ID	Name	City
1	1	john	john	USA	USA
2	2	Mikey	Mikey	USA	USA


But I whant this:

HTML
ID	Name	City
1	john	USA
2	Mikey	USA
Posted
Updated 10-Aug-15 14:46pm
v2

1 solution

i know nothing about PHP, but the docs for fetch array[^] say it defaults to returning an associative AND numeric array, choose either MYSQLI_ASSOC or MYSQLI_NUM
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900