Jump to content

Recommended Posts

I'm using Xampp, have created and populated a database "addtransdb" with a table "addtransinfo" and am trying to use the below program to display the table. It displayed when I created the table (generated by: phpmyadmin 3.2.4 / MYSQL 5.1.41 - SQL quert: SELECT * FROM 'addtransinfo' LIMIT 0,30 ; ) so I guess the problem is here in my program? I don't get an error, I just get nothing. I am running win2000 prof

 

<?
$username="me";
$password="mine";
$database="addtransdb";
mysql_connect("localhost", "root", "");
@mysql_select_db($database) or die( "Unable to select database");
$query=" SELECT * FROM 'addtransinfo';
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();
<html><HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=windows-1252"><!-- this program is designed to show the database contents in a table
<META content="MSHTML 6.00.2800.1649" name=GENERATOR>
<META content="MSHTML 6.00.2800.1649" name=GENERATOR></HEAD>
<BODY><B><FONT size=+2>Project: Hammock Oaks In-house transfers & Add-ons</FONT> 
<FORM>
<TABLE cellSpacing=0 cellPadding=0 border=1>
<TBODY>
<TR>
<TH>Appl</TH>
<TH>.</TH>
<TH>.</TH>
<TH>.</TH>
<TH>Race &</TH>
<TH>Ethnic-</TH>
<TH>.</TH>
<TH>Displ.</TH>
<TH>Income</TH>
<TH>B/r s </TH>
<TH>Movein</TH>
<TH>Removal</TH>
<TH>.</TH>
<TH>.</TH>
<TR>
<TH>#</TH>
<TH>Date</TH>
<TH>Time</TH>
<TH>Name</TH>
<TH>Gender</TH>
<TH>City</TH>
<TH>LH %</TH>
<TH>Y/N</TH>
<TH>Level</TH>
<TH>Needed</TH>
<TH colSpan=2>Date</TH>
<TH>Code</TH>
<TH>Comments</TH></TR></TBODY></TABLE><?
$i=0;
while ($i < $num) {
if ($num==0) {
echo "the database contains no contacts yet";
} else {

$appl=mysql_result($result,$i,"appl");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$name=mysql_result($result,$i,"name");
$racegend=mysql_result($result,$i,"racegend");
$ethnicity=mysql_result($result,$i,"ethnicity");
$laborhsg=mysql_result($result,$i,"laborhsg");
$displ=mysql_result($result,$i,"displ");
$incomelevel=mysql_result($result,$i,"incomelevel" );
$brneeded=mysql_result($result,$i,"brneeded");
$moveindate=mysql_result($result,$i,"moveindate");
$removaldate=mysql_result($result,$i,"removaldate" );
$code=mysql_result($result,$i,"code");
$comments=mysql_result($result,$i,"comments");
?><?
<tr><TD><? echo $appl; ?></TD><TD><? echo $date; ?></TD><TD><? echo $time; ?></TD><TD><? echo $name; ?></TD><TD><? echo $racegend; ?></TD><TD><? echo $ethnicity; ?></TD><TD><? echo $laborhsg; ?></TD><TD><? echo $displ; ?></TD><TD><? echo $incomelevel; ?></TD><TD><? echo $brneeded; ?></TD><TD><? echo $moveindate; ?></TD><TD><? echo $removaldate; ?></TD><TD><? echo $code; ?></TD><TD><? echo $comments; ?></TD></TR><?
$i++;
}
echo "</table>";
$i++;
}
?></B></FORM>
<P></P></BODY></HTML>

Link to comment
https://forums.phpfreaks.com/topic/208781-trying-to-display-database/
Share on other sites

My PHP error reporting is turned on and I get an error on line 76 pointing to the "<" which starts the PHP table? I have another program , almost identical, without HTML , that works?

 

 

<?php
$username="root";
$password="";
$database="addtransdb";

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

$num=mysql_numrows($result);

mysql_close();
?>
    <HTML><HEAD>
<META http<BODY><B><FONT size=+2>Project: Hammock Oaks In-house transfers & Add-ons</FONT> 
<FORM>
<TABLE cellSpacing=0 cellPadding=0 border=1>
  <TBODY>
  <TR>
    <TH>Appl</TH>
    <TH>.</TH>
    <TH>.</TH>
    <TH>.</TH>
    <TH>Race &</TH>
    <TH>Ethnic-</TH>
    <TH>.</TH>
    <TH>Displ.</TH>
    <TH>Income</TH>
    <TH>B/r s </TH>
    <TH>Movein</TH>
    <TH>Removal</TH>
    <TH>.</TH>
    <TH>.</TH>
    </tr><tr>
    <TH>#</TH>
    <TH>Date</TH>
    <TH>Time</TH>
    <TH>Name</TH>
    <TH>Gender</TH>
    <TH>City</TH>
    <TH>LH %</TH>
    <TH>Y/N</TH>
    <TH>Level</TH>
    <TH>Needed</TH>
    <TH colSpan=2>Date</TH>
    <TH>Code</TH>
    <TH>Comments</TH></TR>
    </TBODY></TABLE>
<?
$i=0;
while ($i < $num) {
if ($num==0) {
echo "the database contains no contacts yet";
} else {

$appl=mysql_result($result,$i,"appl");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$name=mysql_result($result,$i,"name");
$racegend=mysql_result($result,$i,"racegend");
$ethnicity=mysql_result($result,$i,"ethnicity");
$laborhsg=mysql_result($result,$i,"laborhsg");
$displ=mysql_result($result,$i,"displ");
$incomelevel=mysql_result($result,$i,"incomelevel");
$brneeded=mysql_result($result,$i,"brneeded");
$moveindate=mysql_result($result,$i,"moveindate");
$removaldate=mysql_result($result,$i,"removaldate");
$code=mysql_result($result,$i,"code");
$comments=mysql_result($result,$i,"comments");

<table>
<tr>
<TD><? echo $appl; ?></TD>
<TD><? echo $date; ?></TD>
<TD><? echo $time; ?></TD>
<TD><? echo $name; ?></TD>
<TD><? echo $racegend; ?></TD>
<TD><? echo $ethnicity; ?></TD>
<TD><? echo $laborhsg; ?></TD>
<TD><? echo $displ; ?></TD>
<TD><? echo $incomelevel; ?></TD>
<TD><? echo $brneeded; ?></TD>
<TD><? echo $moveindate; ?></TD>
<TD><? echo $removaldate; ?></TD>
<TD><? echo $code; ?></TD><TD>
<? echo $comments; ?></TD>
</TR>

$i++;
}

echo "</table>";

$i++;
}

?>
</B></FORM>
<P></P></BODY></HTML>

Again, PLEASE use


tags, you'll see why your program doesnt work with syntax highlighting:

 

<?php
$username="root";
$password="";
$database="addtransdb";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database"); //***didn't i suggest removing the @?***
$query="SELECT * FROM addtransinfo";
$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();
?>
    <HTML><HEAD>
<!--*** notice something wrong below? ***-->
<META http<BODY><B><FONT size=+2>Project: Hammock Oaks In-house transfers & Add-ons</FONT> 
<FORM>
<TABLE cellSpacing=0 cellPadding=0 border=1>
  <TBODY>
  <TR>
    <TH>Appl</TH>
    <TH>.</TH>
    <TH>.</TH>
    <TH>.</TH>
    <TH>Race &</TH>
    <TH>Ethnic-</TH>
    <TH>.</TH>
    <TH>Displ.</TH>
    <TH>Income</TH>
    <TH>B/r s </TH>
    <TH>Movein</TH>
    <TH>Removal</TH>
    <TH>.</TH>
    <TH>.</TH>
    </tr><tr>
    <TH>#</TH>
    <TH>Date</TH>
    <TH>Time</TH>
    <TH>Name</TH>
    <TH>Gender</TH>
    <TH>City</TH>
    <TH>LH %</TH>
    <TH>Y/N</TH>
    <TH>Level</TH>
    <TH>Needed</TH>
    <TH colSpan=2>Date</TH>
    <TH>Code</TH>
    <TH>Comments</TH></TR>
    </TBODY></TABLE>
<?php
$i=0;
while ($i < $num) {
if ($num==0) {
echo "the database contains no contacts yet";
} else {

$appl=mysql_result($result,$i,"appl");
$date=mysql_result($result,$i,"date");
$time=mysql_result($result,$i,"time");
$name=mysql_result($result,$i,"name");
$racegend=mysql_result($result,$i,"racegend");
$ethnicity=mysql_result($result,$i,"ethnicity");
$laborhsg=mysql_result($result,$i,"laborhsg");
$displ=mysql_result($result,$i,"displ");
$incomelevel=mysql_result($result,$i,"incomelevel");
$brneeded=mysql_result($result,$i,"brneeded");
$moveindate=mysql_result($result,$i,"moveindate");
$removaldate=mysql_result($result,$i,"removaldate");
$code=mysql_result($result,$i,"code");
$comments=mysql_result($result,$i,"comments");

// ***you need to close php right here***

<table>
<tr>
<TD><?php echo $appl; ?></TD>
<TD><?php echo $date; ?></TD>
<TD><?php echo $time; ?></TD>
<TD><?php echo $name; ?></TD>
<TD><?php echo $racegend; ?></TD>
<TD><?php echo $ethnicity; ?></TD>
<TD><?php echo $laborhsg; ?></TD>
<TD><?php echo $displ; ?></TD>
<TD><?php echo $incomelevel; ?></TD>
<TD><?php echo $brneeded; ?></TD>
<TD><?php echo $moveindate; ?></TD>
<TD><?php echo $removaldate; ?></TD>
<TD><?php echo $code; ?></TD><TD>
<?php echo $comments; ?></TD>
</TR>

// *** then you'll need to open php again, alternatively you could use heredoc ***

$i++;
}

echo "</table>";

$i++;
}

?>
</B></FORM>
<P></P></BODY></HTML>

 

I've left comments in your code prefixed with ***

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.