Hello, I'm a total newb to PHP and am just clueless here. I'm just trying to show all the data in a table but i'm getting some errors with my current code i'm getting "No Database Selected" and before a warning saying that something was wrong with my while statement.

How should this been written properly?

<?php
$link = mysql_connect('localhost', 'oakshion_user', '*****', 'oakshion_firedata')
	or die("Unable to connect to MySQL");
	
$sql = "SELECT * FROM `firechips_DKP`";

$resault = mysql_query($sql) or die(mysql_error());

echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"themes/FireChips/style/style.css\" />";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#000000\">";
echo "<td>";
echo "<div class=\"border\" bgcolor=\"#000000\" style=\"width: 100%; margin: 0 auto;\">";
echo "	<div class=\"im1\">";
echo "		<div class=\"im2\">";
echo "			<div class=\"im3\">";
echo "				<div class=\"im4\">";
echo "					<div class=\"im5\">";
echo "						<div class=\"im6\">";
echo "							<div class=\"im7\">";
echo "								<div class=\"im8\">";
echo "									<div class=\"tcg\">";
echo "                                    	<p>&nbsp;</p>";
echo "                                    	<p>&nbsp;</p>";
echo "                                   	 	<table width=\"100%\">";
echo "                                   		    <tr>";
echo "                                        		<td width=\"6%\">";
echo "                                                </td>";
echo "                                                <td>";
echo "                                                <table width=\"100%\">";
echo "            										<tr>";
echo "                										<td>";
echo "                                                          <table width=\"100%\">";
echo "            										            <tr>";
echo "                										            <td><div>USERNAME</div></td>";
echo "                                                                  <td><div>GROUP</div></td>";
echo "                                                                  <td><div>GUILD MEMBER</div></td>";
echo "                                                                  <td><div>CURRENT DKP</div></td>";
echo "                                                                  <td><div>TOTAL DKP</div></td>";
echo "                                                                  <td><div>DOWNED BOSSES</div></td>";
echo "                                                                  <td><div>LAST RAID</div></td>";
echo "               									            </tr>";
echo "               									            <tr>";

while($row = mysql_fetch_array($result))
{
	echo "<td><div>".$row['raidMember']."</div></td><td><div>".$row['groupNumber']."</div></td><td><div>".$row['guildMember']."</div></td><td><div>".$row['currentDKP']."</div></td><td><div>".$row['totalDKP']."</div></td><td><div>".$row['downedBosses']."</div></td><td><div>".$row['lastRaid']."</div></td>";
}

echo "               									            </tr>";
echo "                                                          </table>";
echo "                                                  	</td>";
echo "													</tr>";
echo "            									</table>";
echo "                                                </td>";
echo "                                                <td width=\"6%\">";
echo "                                                </td>";
echo "                                    		</tr>";
echo "                                   	 	</table>";
echo "                                    	<p>&nbsp;</p>";
echo "                                    	<p>&nbsp;</p>";
echo "									</div>";
echo "								</div>";
echo "							</div>";
echo "						</div>";
echo "					</div>";
echo "				</div>";
echo "			</div>";
echo "		</div>";
echo "	</div>";
echo "</div>";
echo "</td>";
echo "</table>";

?>

Recommended Answers

All 4 Replies

Friend..
.
.
i thnk u forget to select the database...!!!
.
.
after connecting to the database..u have to select the database also..!!!
.
.
in frst two=three lines you made connection... then u have to select the database also..wid help of mysql_select_db('databasename')..
.
.
then only write the Sql Query..!! :)

Ok well i think its connecting to the database now, but it isn't returning any data, whats wrong?

<?php
mysql_connect('localhost', 'oakshion_user', 'kikiki123^')
	or die("Unable to connect to MySQL");
	
mysql_select_db('oakshion_firedata')
	or die("Unable to select database");
	
$table = "firechips_DKP";
$sql = "SELECT * FROM {$table}"
	or die("Query to show fields from table failed");

$resault = mysql_query($sql) or die(mysql_error());

echo "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"themes/FireChips/style/style.css\" />";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#000000\">";
echo "<td>";
echo "<div class=\"border\" bgcolor=\"#000000\" style=\"width: 100%; margin: 0 auto;\">";
echo "	<div class=\"im1\">";
echo "		<div class=\"im2\">";
echo "			<div class=\"im3\">";
echo "				<div class=\"im4\">";
echo "					<div class=\"im5\">";
echo "						<div class=\"im6\">";
echo "							<div class=\"im7\">";
echo "								<div class=\"im8\">";
echo "									<div class=\"tcg\">";
echo "                                    	<p>&nbsp;</p>";
echo "                                    	<p>&nbsp;</p>";
echo "                                   	 	<table width=\"100%\">";
echo "                                   		    <tr>";
echo "                                        		<td width=\"6%\">";
echo "                                                </td>";
echo "                                                <td>";
echo "                                                <table width=\"100%\">";
echo "            										<tr>";
echo "                										<td>";
echo "                                                          <table width=\"100%\">";
echo "            										            <tr>";
echo "                										            <td><div>USERNAME</div></td>";
echo "                                                                  <td><div>GROUP</div></td>";
echo "                                                                  <td><div>GUILD MEMBER</div></td>";
echo "                                                                  <td><div>CURRENT DKP</div></td>";
echo "                                                                  <td><div>TOTAL DKP</div></td>";
echo "                                                                  <td><div>DOWNED BOSSES</div></td>";
echo "                                                                  <td><div>LAST RAID</div></td>";
echo "               									            </tr>";
echo "               									            <tr>";

while($row = @mysql_fetch_array($result))
{
	echo "<td><div>{$row['raidMember']}</div></td><td><div>{$row['groupNumber']}</div></td><td><div>{$row['guildMember']}</div></td><td><div>{$row['currentDKP']}</div></td><td><div>{$row['totalDKP']}</div></td><td><div>{$row['downedBosses']}</div></td><td><div>{$row['lastRaid']}</div></td>";

}

echo "               									            </tr>";
echo "                                                          </table>";
echo "                                                  	</td>";
echo "													</tr>";
echo "            									</table>";
echo "                                                </td>";
echo "                                                <td width=\"6%\">";
echo "                                                </td>";
echo "                                    		</tr>";
echo "                                   	 	</table>";
echo "                                    	<p>&nbsp;</p>";
echo "                                    	<p>&nbsp;</p>";
echo "									</div>";
echo "								</div>";
echo "							</div>";
echo "						</div>";
echo "					</div>";
echo "				</div>";
echo "			</div>";
echo "		</div>";
echo "	</div>";
echo "</div>";
echo "</td>";
echo "</table>";

?>

Too many errors.
1.

$sql = "SELECT * FROM {$table}"
or die("Query to show fields from table failed");

Thats wrong.

$sql = "SELECT * FROM $table";
$result = mysql_query($sql) or die (mysql_error());

is the right way.
2. You have a typo on line 12. It should be $result.
Btw, You don't have to use { } for your variables.

Your Code

$table = "firechips_DKP";

$sql = "SELECT * FROM {$table}"

or die("Query to show fields from table failed");

$sql = "SELECT * from $table";
$result = mysql_Query($sql) or die('Query error : '.' '.mysql_error());

don't use die with query..!! and don't curly brackets for variable in Query..!! I hope you got my point..!!

and why you echo everytime with html tags..!! u can use html tages outside the php tag...

for example:

<?php
mysql_connect('localhost', 'oakshion_user', 'kikiki123^')

or die("Unable to connect to MySQL");

mysql_select_db('oakshion_firedata')

or die("Unable to select database");

$table = "firechips_DKP";

$sql = "SELECT * FROM $table";

$resault = mysql_query($sql) or die(mysql_error());
 
?>  <!-- close php code and start html code directly
-->
<link rel="stylesheet" type="text/css" href="themes/FireChips/style/style.css" >

<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="000000">"

<td>

<div class="border" bgcolor="000000" style="width: 100%;margin: 0 auto;">

 <div class="im1">

 <div class="im2">

</td>
<tr>
     <td>Firstname</td>
       <td>Lastname</td>
</tr>
<tr>
<!-- now you want to fetch your data from database and for that you need php then again start php code -->

<?while($row = mysql_fetch_array($result)) 
 
{     ?>
<td><? echo $row['firstname']?></td>
<td><? echo $row['lastname']?></td>

<? } ?>

</tr>

i hope this will simplify your work... and i think you understand what i want to say..!! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.