Page 1 of 1

Trouble with fetching row (for)

Posted: Tue Jul 20, 2004 4:20 pm
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

Posted: Tue Jul 20, 2004 4:29 pm
by kettle_drum
You dont have the closing bracket for:

Code: Select all

for ($i=0; $i < mysql_num_rows($result); $i++){

Posted: Tue Jul 20, 2004 4:45 pm
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.

Posted: Tue Jul 20, 2004 9:57 pm
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? :?

Posted: Tue Jul 20, 2004 10:02 pm
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.

Posted: Tue Jul 20, 2004 10:05 pm
by John Cartwright
w00t never knew that :P

Posted: Tue Jul 20, 2004 10:10 pm
by evilmonkey
Ah, that's nice to know, makes the script marginally faster...

*goes to change his central sql function*