Page 1 of 1
HTML Table /w mySQL.. help.. noob
Posted: Mon Aug 05, 2002 11:46 pm
by Exodus00
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
Posted: Tue Aug 06, 2002 12:37 am
by learning_php_mysql
you need a nested loop like.....
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>");
}
maybe that will help =/
Posted: Tue Aug 06, 2002 2:05 am
by twigletmac
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
Posted: Tue Aug 06, 2002 9:13 pm
by Exodus00
ok heres whats before the HTML. Thanx for replying.
Code: Select all
<?php
# Name
$db = "registered";
# Host
$host = "localhost";
# Username
$usr = "";
# Password
$pwd = "";
# Table
$table = "";
# connect
$cid = mysql_connect($host,$usr,$pwd);
?>
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

Posted: Wed Aug 07, 2002 1:43 am
by twigletmac
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():
Code: Select all
mysql_select_db('your_db_name_here') or die(mysql_error());
then you can set up your query (assuming usernumber, callsign, clan and age are the names of the fields whose information you want):
Code: Select all
$sql = "SELECT usernumber, callsign, clan, age FROM account";
and execute it using
mysql_query():
Code: Select all
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Then to get the results you would most likely use
mysql_fetch_assoc() in a while loop:
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>';
}
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
Posted: Wed Aug 07, 2002 9:38 am
by Exodus00
I have to go to work right now but I'll try that tonight. It looks promising. Thanks a ton, i'll keep you updated.

Posted: Wed Aug 07, 2002 10:56 pm
by Exodus00
Thanx a TON!!!, it worked perfectly the first time i tried. I also read the notes so I learned what I wasn't doing. Thanx again, that really helped me out.