HTML Table /w mySQL.. help.. noob
Moderator: General Moderators
HTML Table /w mySQL.. help.. noob
ok.. i read the other one posted.. but it wasn't with mySQL.. and I haven't even begun to look at ODBC... not a real microsoft fan, but.. maybee someday I might get around to it. Anyway... heres my code.. minus the database login info.. but I cant figure out whats wrong.. it keeps giving me an error near line 108, which i'll specify.. giving me a parse error.... I'll let you take a look at it.. its probably something really stupid and dumb.
this is basically the part giving me the errors...
<?php
Line 108* SELECT count(*) FROM account;
# Make the cells for each peice of data
print "<TR>\n";
foreach ("usernumber") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$usernumber</TD>\n"; }
foreach ("callsign") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$callsign</TD>\n"; }
foreach ("clan") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$clan</TD>\n"; }
foreach ("age") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$age</TD>\n"; }
print "</TR>\n";
}
?>
the columns i want posted have the names, usernumber, callsign, clan, age
if.. you have anymore questions I'll do the best to answer em.. any help whatsoever would be appreciated.. thanx
edit: this is all within a table already.. i just didn't post the HTML
this is basically the part giving me the errors...
<?php
Line 108* SELECT count(*) FROM account;
# Make the cells for each peice of data
print "<TR>\n";
foreach ("usernumber") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$usernumber</TD>\n"; }
foreach ("callsign") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$callsign</TD>\n"; }
foreach ("clan") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$clan</TD>\n"; }
foreach ("age") { print "<TD WIDTH=\"25%\" ALIGN=\"CENTER\">$age</TD>\n"; }
print "</TR>\n";
}
?>
the columns i want posted have the names, usernumber, callsign, clan, age
if.. you have anymore questions I'll do the best to answer em.. any help whatsoever would be appreciated.. thanx
edit: this is all within a table already.. i just didn't post the HTML
-
learning_php_mysql
- Forum Commoner
- Posts: 27
- Joined: Sun Aug 04, 2002 12:58 pm
- Location: WA
you need a nested loop like.....
maybe that will help =/
Code: Select all
for($row=0; $row<$whatever; $row++) {
echo("<tr>");
for($col=0; $col<$whenever; $col++) {
echo("\n\t<td>");
echo("stuff in cell");
echo("</td>\n");
}
echo("</tr>");
}- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Hiya, need a little bit more information. Specifically, what is the exact error message and what exactly does line 108 and the lines above it and below it look like (not all 107+ just maybe the lines 100-115 or something). I think you may be having a problem with getting the information from the database. There's a few things I've noticed but I'd like to see more code.
Mac
Mac
ok heres whats before the HTML. Thanx for replying.
then inside the html table is what i had above and thats it...
then heres teh error, word for word
Parse error: parse error in /usr/local/psa/home/vhosts/oregonlan.ws/httpdocs/registered.php on line 108
i've been looking at the connection script.. I got that part from somewhere and put it in this.. but seem to have ommitted some peices now that i look at it..... the way they have it setup on the other application, i dont even think it will work with this....... but anyway... i'll post more if you need more.. trying to figure this out myself too with my PHP book, but its kinda hard to know where to look when i dont really know what i'm looking for
Code: Select all
<?php
# Name
$db = "registered";
# Host
$host = "localhost";
# Username
$usr = "";
# Password
$pwd = "";
# Table
$table = "";
# connect
$cid = mysql_connect($host,$usr,$pwd);
?>then heres teh error, word for word
Parse error: parse error in /usr/local/psa/home/vhosts/oregonlan.ws/httpdocs/registered.php on line 108
i've been looking at the connection script.. I got that part from somewhere and put it in this.. but seem to have ommitted some peices now that i look at it..... the way they have it setup on the other application, i dont even think it will work with this....... but anyway... i'll post more if you need more.. trying to figure this out myself too with my PHP book, but its kinda hard to know where to look when i dont really know what i'm looking for
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Once you've done your connection to the MySQL database (the mysql_connect() part) you need a line in which you select a database using mysql_select_db():
then you can set up your query (assuming usernumber, callsign, clan and age are the names of the fields whose information you want):
and execute it using mysql_query():
Then to get the results you would most likely use mysql_fetch_assoc() in a while loop:
I've added in stripslashes() and htmlspecialchars() to the lines of code which retrieve information use these where necessary depending on the data coming out of the database.
If you use the links to the manual pages within this post you will find lots more examples. If you need help structuring an SQL query start with learning about SELECT at mysql.com.
Mac
Code: Select all
mysql_select_db('your_db_name_here') or die(mysql_error());Code: Select all
$sql = "SELECT usernumber, callsign, clan, age FROM account";Code: Select all
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');Code: Select all
while ($row = mysql_fetch_assoc($result)) {
$usernumber = $rowї'usernumber'];
$callsign = stripslashes($rowї'callsign']);
$clan = htmlspecialchars(stripslashes($rowї'clan']));
$age = $rowї'age'];
// Now do the HTML
echo '<tr>';
echo '<td width="25%" align="center">'.$usernumber.'</td>';
echo '<td width="25%" align="center">'.$callsign.'</td>';
echo '<td width="25%" align="center">'.$clan.'</td>';
echo '<td width="25%" align="center">'.$age.'</td>';
echo '</tr>';
}If you use the links to the manual pages within this post you will find lots more examples. If you need help structuring an SQL query start with learning about SELECT at mysql.com.
Mac