0

Hi,
I'm having some problem with this code:

<?PHP

include 'topo.php';

include 'db_connect.php';

?>

<table>
	<tr>
		<td id="navigation-block">
				<img src="background.jpg" id="hide" />
					<ul id="sliding-navigation">
					<?PHP
	
					$sql = "SELECT * FROM cursos";
					$query = mysql_query($sql,$connect);
					
					while ($row = mysql_fetch_array($query))
					{ 
					?>
						<li class="sliding-element"><a href="prog_curso.php?cod= <?PHP echo $row['cod_curso']; ?> "> <?PHP echo $row['nome_curso']; ?> </a></li>
					<?PHP
					;}
					?>
					</ul>
			</div>
		</td>
		
		<td width="5%">
		</td>
		
		<td>
		PROGRAMAÇÃO:
		<br/>
		<?PHP
	
		$sql_prog = "SELECT prog_curso FROM cursos WHERE cod_curso=".$row['cod_curso'];
		$query_prog = mysql_query($sql_prog, $connect);
					
		while ($row = mysql_fetch_array($query_prog))
		{ 
			echo $row['prog_curso']; 
		}
		?>
		</td>
	</tr>
	
	
</table>

<?PHP

include 'rodape.php';

?>

Gives me this error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\site\prog_curso.php on line 41

Line 41:

while ($row = mysql_fetch_array($query_prog))
2
Contributors
7
Replies
8
Views
5 Years
Discussion Span
Last Post by broj1
0

The line $query_prog = mysql_query($sql_prog, $connect); returns false instead of a valid resource (and stores it in $query). The reason could be error in your sql statement ($sql) or error in your connection ($connect). You should check for existence of a valid resource before running a while loop:

if($query_prog) {

    while($row = mysql_fetch_array($query_prog)) {

        // ...
    }
} else {

    echo 'Something went wrong!';
}

Also check the correctness of your query in phpmyadmin or mysql client

Edited by broj1: Typos as usual

0

The line $query_prog = mysql_query($sql_prog, $connect); returns false instead of a valid resource (and stores it in $query). The reason could be error in your sql statement ($sql) or error in your connection ($connect). You should check for existence of a valid resource before running a while loop:

if($query_prog) {

    while($row = mysql_fetch_array($query_prog)) {

        // ...
    }
} else {

    echo 'Something went wrong!';
}

Also check the correctness of your query in phpmyadmin or mysql client

I tried the "Something went wrong!" and that's the sentence that appears instead of the program...

0

Put this on line 37 to debug:

die($sql_prog)

It should display your query. Paste it here (and also into myphpadmin to see if it returns anything). I have a feeling that $row['cod_curso'] does not contain what you are expecting.

0

Put this on line 37 to debug:

die($sql_prog)

It should display your query. Paste it here (and also into myphpadmin to see if it returns anything). I have a feeling that $row['cod_curso'] does not contain what you are expecting.

Error:

Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\site\prog_curso.php on line 38

0

Sorry my mistake. Put that code after line 38 just after the following line:

$sql_prog = "SELECT prog_curso FROM cursos WHERE cod_curso=".$row['cod_curso'];
die($sql_prog);

Edited by broj1: n/a

0

Sorry my mistake. Put that code after line 38 just after the following line:

$sql_prog = "SELECT prog_curso FROM cursos WHERE cod_curso=".$row['cod_curso'];
die($sql_prog);

I writes on the page:

SELECT prog_curso FROM cursos WHERE cod_curso=
0

This query indeed contains an error since there is no value for curso field - $row does not return anything - probably since it is outside the first while loop. Depending on what you want you should assign $row either to a variable or to an array within the first while loop and then use it in the second query.

Edited by broj1: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.