GIDForums  

Go Back   GIDForums > Webmaster Forums > Web Design Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 20-Mar-2004, 07:59
mdonovan mdonovan is offline
New Member
 
Join Date: Mar 2004
Posts: 1
mdonovan is on a distinguished road

loading an html file from a db using php


Hi All,

I am new to this web stuff so be patient. All I am trying to do is load a table with the results of my SQL query. Here is the code.

Thanks for you help !!

PHP Code:

<?php require_once('Connections/stpaulconnection.php');

    mysql_select_db($database_stpaulconnection, $stpaulconnection);
    $my_query = "SELECT * FROM Registration";
    $result = mysql_query($my_query, $stpaulconnection);
 ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
    <body>
    <?php 
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) ;  
    ?>          
    <table>
        <tr>
        <td>
        <?php $row["Lastname"] ?>
        </td>
        <td>
        <?php $row["Firstname"] ?>
        </td>
        </tr>
    </table>
</body>
</html>
  #2  
Old 20-Mar-2004, 17:41
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello mdonovan,

Try changing this:

PHP Code:

<?php
  while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) ;  
  ?>      
  <table>
    <tr>
    <td>
    <?php $row["Lastname"] ?>
    </td>
    <td>
    <?php $row["Firstname"] ?>
    </td>
    </tr>
  </table>

to this:

PHP Code:

<table>
<?php while( $row=mysql_fetch_assoc($result) ): ?>
  <tr>
    <td><?php echo $row["Lastname"]; ?></td>
    <td><?php echo $row["Firstname"]; ?></td>
  </tr>
<?php endwhile; ?>
</table> 

  #3  
Old 20-Mar-2004, 19:47
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Curious... Does:

PHP Code:

<tr>
    <td>
    <?php $row["Lastname"] ?>
    </td>
    <td>
    <?php $row["Firstname"] ?>
    </td>
    </tr> 


and

PHP Code:

<tr>
    <td><?php echo $row["Lastname"]; ?></td>
    <td><?php echo $row["Firstname"]; ?></td>
  </tr> 


Make a difference how it displays? Also, why have a space between the ';' and '?'

;SPACE?> What would happen if there was not a space?
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #4  
Old 21-Mar-2004, 07:07
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Quote:
Originally Posted by BobbyDouglas
...
Make a difference how it displays? Also, why have a space between the ';' and '?'

;SPACE?>
Except that the opening and closing <td> will be on the same line, there wouldn't appear to be anything different on the web page itself. I put the space in to keep the code easier for me to read. No other reason...

Quote:
What would happen if there was not a space?
Nothing much, see above...
  #5  
Old 21-Mar-2004, 11:17
BobbyDouglas's Avatar
BobbyDouglas BobbyDouglas is offline
Regular Member
 
Join Date: Aug 2003
Posts: 789
BobbyDouglas has a spectacular aura aboutBobbyDouglas has a spectacular aura about
Interesting... Thanks for the clarification
__________________
Mr. Bob's Web Design - Tirelessly looking for ways to enhance the customer base of your business.
  #6  
Old 21-Mar-2004, 12:16
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Quote:
Originally Posted by JdS
Except that the opening and closing <td> will be on the same line, there wouldn't appear to be anything different on the web page itself. I put the space in to keep the code easier for me to read. No other reason...
But they don't display the same.
PHP Code:

<td>
    <?php $row["Lastname"] ?>
    </td> 

will display "[space]lastnamne[space]" whereas
PHP Code:

<td><?php $row["Lastname"] ?></td> 

will display "lastnamne".

In general this difference is not noticed unless 'lastname' splits onto two lines.
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #7  
Old 21-Mar-2004, 20:25
cs2 cs2 is offline
Member
 
Join Date: May 2003
Location: California
Posts: 107
cs2 will become famous soon enough
Quote:
Originally Posted by WaltP
PHP Code:

<td>
    <?php $row["Lastname"] ?>
    </td> 

will display "[space]lastnamne[space]" whereas
PHP Code:

<td><?php $row["Lastname"] ?></td> 

will display "lastnamne".
How does it display anything? There's no 'echo' or 'return' in that code!
__________________
The Whole Internet, LLC
Visit our Homepage, -or-
use our online CSS Editor
  #8  
Old 21-Mar-2004, 20:53
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Walt, I must admit you made me unsure of what I had written earlier (I tend to overlook details)... so I quickly cooked up a sample HTML page and was relieved to find out that this time, I was NOT wrong. The table cells are displayed the same regardless of the extra lines and spaces in the HTML itself.

Here's the example HTML...

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Does the space matter?</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <style> <!-- td { background-color:yellow; } table { width:75px;background-color:blue; } --> </style> </head> <body> <div>With spaces... <table> <tr> <td> de Silva </td> </tr> <tr> <td> van der Zwaard </td> </tr> </table></div> <div>NO spaces... <table> <tr><td>de Silva</td></tr> <tr><td>van der Zwaard</td></tr> </table></div> </body> </html>

I've viewed the page with Mozilla and Internet Explorer and didn't find any difference with either.
  #9  
Old 21-Mar-2004, 23:38
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
How interesting! I distinctly remember the beginning and ending spaces and/or newlines adding a space before the contents of the TD. Maybe I'm remembering NS4... I'll now have to remember not to worry about leading spaces.

Thanks J
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
CD burner wont burn!! robertli55 Computer Hardware Forum 1 18-Jun-2004 10:53
Yet another CD burner problem: Lite-On LSC-24082K Erwin Computer Hardware Forum 1 22-May-2004 11:28
Re: Programming Techniques WaltP C Programming Language 0 09-Mar-2004 23:56
html to php tenaki Web Design Forum 17 28-Oct-2003 16:18
How Do i get php to find out the file type of a file for me? viperman95833 MySQL / PHP Forum 2 08-Mar-2003 09:48

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.