selecting a whole table?
Posted: Mon May 19, 2003 4:41 am
if i want to select and display a whole table is this correct?
Code: Select all
$query = "SELECT * FROM users"A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$query = "SELECT * FROM users"Code: Select all
$query = "SELECT * FROM users";
$result = mysql_query($query, $db_conn);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++)
{
echo "<table cellspacing="0" cellpadding="0"><tr><td>$rowї'username']</td>";
echo "<td>$rowї'charname']</td></tr></table>";
}
?>Code: Select all
echo '<table cellspacing="0" cellpadding="0"><tr><td>'.$row['username'].'</td>';
echo '<td>'.$row['charname'].'</td></tr></table>';Code: Select all
echo "<table cellspacing="0" cellpadding="0"><tr><td>$row[username]</td>";
echo "<td>$row[charname]</td></tr></table>";Code: Select all
echo "<table cellspacing="0" cellpadding="0"><tr><td>{$row['username']}</td>";
echo "<td>{$row['charname']}</td></tr></table>";Hey, the query was correct to select the whole page...[]InTeR[] wrote:Yep
I tend to use single quotes or here document format as it means I don't have to escape quotes in HTML and with my syntax highlighter concenating the variables means I can see them easily. But it'll come down to what you find easiest to use:irealms wrote:thats great thanks![]()
i've always wondered what those in the first case were for when i've seen them used. Which of the 3 would you advise to use
Code: Select all
<table cellspacing="5" cellpadding="5"><tr><td><div class="log"><u>Username</u></div></td><td><div class="log"><u>Main character name</u></div></td></tr></table>
<?
ob_start();
session_start();
//show members
$query = "SELECT * FROM users";
$result = mysql_query($query, $db_conn);
$num_results = mysql_num_rows($result);
$row = mysql_fetch_array($result);
for ($i=0; $i <$num_results; $i++)
{
echo "<table cellspacing="5" cellpadding="5"><tr><td><div class="log">$rowїusername]</div></td>";
echo "<td><div class="log">$rowїcharname]</div></td></tr></table>";
}
?>Code: Select all
<table cellspacing="5" cellpadding="5"><tr><td><div class="log"><u>Username</u></div></td><td><div class="log"><u>Main character name</u></div></td></tr></table>
<?php
// if you can avoid having to use ob_start() by putting session_start() at the
// very top of the script (perhaps in a config file which is called before
// anything else) it would be better IMHO
ob_start();
session_start();
//show members
// Personally I would specify all of the fields that I want to (or expect to)
// return from the table.
$query = "SELECT username, charname FROM users";
$result = mysql_query($query, $db_conn);
// you're looping through the whole result so you can use a while loop
while ($row = mysql_fetch_assoc($result))
{
echo "<table cellspacing="5" cellpadding="5"><tr><td><div class="log">$row[username]</div></td>";
echo "<td><div class="log">$row[charname]</div></td></tr></table>";
}
?>