User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,940 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,669 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting

php query headers

Join Date: Jan 2008
Posts: 76
Reputation: rickarro is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
rickarro rickarro is offline Offline
Junior Poster in Training

Re: php query headers

  #3  
May 6th, 2008
Ok, i think I answered my own question, someone please tell me if this was the wrong way to do this, but it works.
// open connection 
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); 

// select database 
mysql_select_db($db) or die ("Unable to select database!"); 

// create query 
$query = "SELECT * FROM people ORDER BY fname ASC"; 

// execute query 
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); 

// see if any rows were returned 
if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table cellpadding=10 border=0>";
//I ADDED THE ECHO'S BELOW TO CREATE MY TABLE HEADINGS
//Before the "While" statement displays the headings just once at the top of the page.
    echo "<tr>";
    echo "<td><strong>First Name</strong></td>"; 
    echo "<td><strong>Last Name</strong></td>";
    echo "<td><strong>Phone Number</strong></td>";
    echo "<td><strong>Extension</strong></td>";
    echo "<td><strong>Title</strong></td>";
    echo "<td><strong>Department</strong></td>";
    echo "<td><strong>Fax Number</strong></td>";
    echo "</td>";
    while($row = mysql_fetch_row($result)) {
	    echo "<tr>"; 
        echo "<td>".$row[1]."</td>"; 
        echo "<td>".$row[2]."</td>"; 
        echo "<td>".$row[3]."</td>";
        echo "<td>".$row[4]."</td>";
        echo "<td>".$row[5]."</td>";
        echo "<td>".$row[6]."</td>";
        echo "<td>".$row[7]."</td>";
        echo "</tr>"; 
    } 
    echo "</table>"; 
} 
else { 
    // no 
    // print status message 
    echo "No rows found!"; 
} 

// free result set memory 
mysql_free_result($result); 

// close connection 
mysql_close($connection); 

?> 
I added my heading tags between my open table tag and my while statement. This displays the headings only once at the top of the page. This solved my problem, but is it the correct way to do this. Pointers would be appreciated.

Thanks,
Reply With Quote  
All times are GMT -4. The time now is 6:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC