PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Draco_03
Forum Regular
Posts: 577 Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada
Post
by Draco_03 » Tue Jul 20, 2004 4:20 pm
Code: Select all
<?php
$host = "localhost";
$user = "xxx";
$pswd = "xxx";
$dbname = "xxx";
$connect = mysql_connect($host, $user, $pswd)
or die("Could not connect: " . mysql_error());
$database = mysql_select_db("$dbname")
or die(MySQL_Error());
$username = $_POST["username"];
$password = $_POST["password"];
$sql = "SELECT * FROM edh_centres";
$result = mysql_query($sql) or die("nothing in the database");
echo ("<table width="100%" border="0" cellspacing="0" cellpadding="0">");
for ($i=0; $i < mysql_num_rows($result); $i++){
$row = mysql_fetch_row($result);
echo("
<tr>
<td>$row[1]</td>
<td>$row[2]</td>
<td>$row[3]</td>
<td>$row[4]</td>
<td>$row[5]</td>
<td>$row[6]</td>
<td>$row[7]</td>
</tr>
");
mysql_close($connect);
?>
give me an error
Parse error: parse error, unexpected $ in /home/daniel12/public_html/zoro/center.php on line 48
wich is the last line of my code
kettle_drum
DevNet Resident
Posts: 1150 Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England
Post
by kettle_drum » Tue Jul 20, 2004 4:29 pm
You dont have the closing bracket for:
Code: Select all
for ($i=0; $i < mysql_num_rows($result); $i++){
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue Jul 20, 2004 4:45 pm
Code: Select all
for($i = 0, $num = mysql_num_rows($result); $i < $num; $i++)would reduce the hit to mysql a bit, too.
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Tue Jul 20, 2004 9:57 pm
feyd wrote: Code: Select all
for($i = 0, $num = mysql_num_rows($result); $i < $num; $i++)would reduce the hit to mysql a bit, too.
What difference does it make?
d3ad1ysp0rk
Forum Donator
Posts: 1661 Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA
Post
by d3ad1ysp0rk » Tue Jul 20, 2004 10:02 pm
If it's in the second parameter, it gets calculated each run through, when it's in the first, it's only done once.
evilmonkey
Forum Regular
Posts: 823 Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada
Post
by evilmonkey » Tue Jul 20, 2004 10:10 pm
Ah, that's nice to know, makes the script marginally faster...
*goes to change his central sql function*