big-dog1965 Posted January 14, 2010 Share Posted January 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/ Share on other sites More sharing options...
trq Posted January 14, 2010 Share Posted January 14, 2010 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']; } } } Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-994703 Share on other sites More sharing options...
big-dog1965 Posted January 14, 2010 Author Share Posted January 14, 2010 I dont understand how that would show the data in my table in the cells I need it to Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-994713 Share on other sites More sharing options...
oni-kun Posted January 14, 2010 Share Posted January 14, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-994716 Share on other sites More sharing options...
big-dog1965 Posted January 14, 2010 Author Share Posted January 14, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-994722 Share on other sites More sharing options...
Buddski Posted January 14, 2010 Share Posted January 14, 2010 You need to place your tr and td tags inside the while loop so each iteration will produce a table row. like this while ($row = mysql_fetch_assoc($result)) { echo '<tr><td>'.$row['name'].'</td></tr>'; } Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-994804 Share on other sites More sharing options...
big-dog1965 Posted January 14, 2010 Author Share Posted January 14, 2010 resolved thank you Quote Link to comment https://forums.phpfreaks.com/topic/188422-echoing-results-from-db/#findComment-995073 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.