Jump to content

how to list information from a mysql row


madspof

Recommended Posts

am i going about listing data from a mysql row the right way this is what i have so far:

 

<?php 
include("connect.php");
$tbl_name = "userdata";
$res = mysql_query("select userid from $tbl_name"); 
while($row = mysql_fetch_array($res, MYSQL_ASSOC))
{
    echo "Name :{$row['userid']} <br>" .
} 
?>

Link to comment
https://forums.phpfreaks.com/topic/67140-how-to-list-information-from-a-mysql-row/
Share on other sites

here is some code I use, I organized my data into an html table

 

 

<?php
// Connecting, selecting database
$link = mysql_connect('localhost', 'testUser', '*****')
   or die('Could not connect: ' . mysql_error());

mysql_select_db('database') or die('Could not select database');

$validUser = $_SESSION['validUser'];

$query = "SELECT name,repNumber,address,city,state,zip,contactNumber,email,numberOfCoupons,signUpDate FROM business WHERE userName='$validUser'";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());

// Printing results in HTML
echo "<p> </p>";
echo "<table border='1' align='center'>\n";
echo "<tr align='center'>\n";
echo "<td>Business Name</td>\n";
echo "<td>Rep Number</td>\n";
echo "<td>Address</td>\n";
echo "<td>City</td>\n";
echo "<td>State</td>\n";
echo "<td>Zip Code</td>\n";
echo "<td>Contact Number</td>\n";
echo "<td>Email</td>\n";
echo "<td>Coupons</td>\n";
echo "<td>SignUp Date</td>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "\t<tr align='center'>\n";
   foreach ($line as $col_value) {
       echo "\t\t<td>$col_value</td>\n";
   }
   echo "\t</tr>\n";
}
echo "</table>\n";

?>

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.