Jump to content

php code for sql output to table.


Birdmansplace

Recommended Posts

For some reason i cant figure out why its not getting info from mysql table.

 

<br />
<div align="center">
<table style="width 87%" border="1" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Entrys &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 User Name &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Amount &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Date &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Trans Type &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Trans Type &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Trans Type &#8226</th>
<th><font face="Arial, Helvetica, sans-serif">&#8226 Trans Type &#8226</th>
</tr>
<?
ini_set("display_errors", "1");
error_reporting(E_ALL);

include("dbinfo.php");

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM schedule";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {

$day1=mysql_result($result,$i,'day1');
$day2=mysql_result($result,$i,'day2');
$day3=mysql_result($result,$i,'day3');
$day4=mysql_result($result,$i,'day4');
$day5=mysql_result($result,$i,'day5');
$day6=mysql_result($result,$i,'day6');
$day7=mysql_result($result,$i,'day7');
$day8=mysql_result($result,$i,'day8');
?>
<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day1; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day2; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day3; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day4; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day5; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day6; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day7; ?></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $day8; ?></td>
</tr>

<?
$i++;}
echo "</table>";
?>

</div>


 

nothing from database loads on page.  What did i do wrong?  Using old code from another project and it works using the old fields, db, and table.  just coped and pasted in to a new file and changed to fit new database and table.

Link to comment
https://forums.phpfreaks.com/topic/186153-php-code-for-sql-output-to-table/
Share on other sites

Debug your code;

 

1. add "or die()" function:

mysql_query("...") or die(mysql_error());

 

2. Echo Specific Variables to check their values.

// Before the loop
echo($num);

// Inside the loop
echo($i);

 

3. Try the query using phpmyadmin.

 

You may find that there is a typo (Case-sensitive, o doesnt equal O).

 

-CB-

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.