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
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-

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.