Jump to content

ECHOING RESULTS FROM DB


big-dog1965

Recommended Posts

How do I get this code to echo the data in the database

Or why doesnt it echo the data

 

<?php
include("config.inc.php");

mysql_connect(localhost,$username,$password,$dbname);
@mysql_select_db($dbname) or die( "Unable to select database");
$query= 'SELECT FullName, Address, City, Phone FROM Signatures ORDER BY FullName DESC LIMIT 0, 100';
mysql_query($query);
?>

<table width="100%">
<tr><td width="31%">
	<img border="0" src="../images/space.gif" width="200" height="50"></td>
<td width="28%"> </td>
<td width="18%"> </td>
<td width="21%">
<p align="right"></td></tr>
<tr><td width="98%" colspan="4">
<font face='arial' size=2>
	<b></b></td>
</tr>
<tr><td width="31%" bgcolor="#CCCCCC"><b>Full Name:</b></td>
<td width="28%" bgcolor="#CCCCCC"><b>Address:</b></td>
<td width="18%" bgcolor="#CCCCCC"><b>City:</b></td>
<td width="21%" bgcolor="#CCCCCC"><b>Phone:</b></td></tr>
<tr><td width="31%"> <?php echo $FullName; ?></td><td width="28%"><?php echo $Address; ?></td>
<td width="18%"><?php echo $City; ?></td><td width="21%"><?php echo $Phone; ?></td></tr>
</table>

<?php 

Link to comment
https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/
Share on other sites

I'm just going to give you a simple example which you can rework to your needs.

 

$sql = "SELECT foo FROM table";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    while ($row = mysql_fetch_assoc($result)) {
      echo $row['foo'];
    }
  }
}

I dont understand how that would show the data in my table in the cells I need it to

 

The query will pull the data from the table, mysql_fetch_assoc will return the cells in the database into an array.

 

    while ($row = mysql_fetch_assoc($result)) {
      echo $row['foo'];
    }

 

This will display the row 'foo' within 'table'. Simple example.

 

 

Guess Im still missing something. If I use the excample provided it does display the FullName for excample but at the top of the page above the table I want the data to be in. If you look at my code I was trying to use where you see <?php echo $FullName; ?> is in a cell in the table. My table has a header row FullName Address and so on under eah header I want the database data to populate

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.