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))

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

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...

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.

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

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);

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=

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.