madspof Posted August 28, 2007 Share Posted August 28, 2007 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>" . } ?> Quote Link to comment https://forums.phpfreaks.com/topic/67140-how-to-list-information-from-a-mysql-row/ Share on other sites More sharing options...
Asperon Posted August 28, 2007 Share Posted August 28, 2007 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/67140-how-to-list-information-from-a-mysql-row/#findComment-336717 Share on other sites More sharing options...
Asperon Posted August 28, 2007 Share Posted August 28, 2007 you define you table titles, and then you have the loop fill in the fields below for however many rows you have Quote Link to comment https://forums.phpfreaks.com/topic/67140-how-to-list-information-from-a-mysql-row/#findComment-336718 Share on other sites More sharing options...
madspof Posted August 28, 2007 Author Share Posted August 28, 2007 if i only want two list 3 rows and if their name where userid picurl and date what wud i have to do Quote Link to comment https://forums.phpfreaks.com/topic/67140-how-to-list-information-from-a-mysql-row/#findComment-336741 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.