Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP script to print contents of a table?
Old 12-14-2009, 09:33 PM PHP script to print contents of a table?
Junior Talker

Posts: 2
Name: Chris
Trades: 0
I tried to upload this script but the only thing that was printed on the website was 'BEST OF THE BEST' ? what am I doing wrong?

<?
$username="xxxxxx";
$password="xxxxxx";
$database="indoorsoccerforum_com_au_fivedock";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM BEST OF THE BEST";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

echo "<b><center>BEST OF THE BEST</center></b><br><br>";
$i=0;
while ($i < $num) {
$team=mysql_result($result,$i,"TEAM");
$winpercentage=mysql_result($result,$i,"WIN PERCENTAGE");
$for=mysql_result($result,$i,"For");
$against=mysql_result($result,$i,"Against");

echo "<b>Team: $team</b><br>WIN PERC: $winpercentage<br>FOR: $for<br> AGAINST: $against<br><hr><br>";
$i++;
}
?>
ceevee is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-15-2009, 12:00 AM Re: PHP script to print contents of a table?
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Hmm, i'm pretty sure you can't have spaces in table names, or in field names. Try renaming your table to, for example, "BestOfTheBest".
It's generally a bad idea to use '@', especially when developing, since it will suppress errors and warnings.

I made some small modifications, try this code instead.
PHP Code:
<?
$username
="xxxxxx";
$password="xxxxxx";
$database="indoorsoccerforum_com_au_fivedock";
mysql_connect(localhost,$username,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$query="SELECT *  FROM BestOfTheBest";
$result=mysql_query($query) or die(mysql_error());
mysql_close();
 
echo 
"<b><center>BEST OF THE BEST</center></b><br><br>";
while (
$row mysql_fetch_assoc($result)) {
$team $row['team'];
$winpercentage $row['win_perentage'];
$for $row['for'];
$against $row['against'];

echo 
"<b>Team: $team</b><br>WIN PERC: $winpercentage<br>FOR: $for<br> AGAINST: $against<br><hr><br>";
$i++;
}
?>
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 12-20-2009, 02:39 AM Re: PHP script to print contents of a table?
freezea's Avatar
Experienced Talker

Posts: 45
Trades: 0
<?
//MyDB represents the name of your database.
//MyTable represents the name of your table inside the database.
mysql_connect("localhost","","") or die("Unable to connect to SQL server");
@mysql_select_db("MyDB") or die("Unable to select database");
$result = mysql_query("select * from MyTable limit 100");
?>
<table border="1">
<tr>
<?
while ($field=mysql_fetch_field($result)) {
echo "<th>";
echo "$field->name";
echo "</th>";
}
echo "</tr>";
while ($row = mysql_fetch_row($result)) {
echo "<tr>";
for ($i=0; $i<mysql_num_fields($result); $i++) {
echo "<td>";
echo "$row[$i]";
echo "</td>";
}
echo "</tr>\n";
}
echo "</table>";
?>
__________________

Please login or register to view this content. Registration is FREE
: Web-based Excel-like Java reporting tool.
freezea is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP script to print contents of a table?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.19510 seconds with 12 queries