Trouble with fetching row (for)

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

Post Reply
Draco_03
Forum Regular
Posts: 577
Joined: Fri Aug 15, 2003 12:25 pm
Location: Montreal, Canada

Trouble with fetching row (for)

Post by Draco_03 »

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 »

You dont have the closing bracket for:

Code: Select all

for ($i=0; $i < mysql_num_rows($result); $i++){
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

for($i = 0, $num = mysql_num_rows($result); $i < $num; $i++)
would reduce the hit to mysql a bit, too.
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

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 »

If it's in the second parameter, it gets calculated each run through, when it's in the first, it's only done once.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

w00t never knew that :P
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

Ah, that's nice to know, makes the script marginally faster...

*goes to change his central sql function*
Post Reply