Jump to content
  • Revista PROGRAMAR: Já está disponível a edição #60 da revista programar. Faz já o download aqui!

Sign in to follow this  
Sir Pereira

"Editar notícia" correspondente a ID

Recommended Posts

Sir Pereira

Boas pessoal,

tenho o seguinte código:

		<a class="button" onmouseover='this.style.cursor="pointer" ' onfocus='this.blur();' onclick="document.getElementById('adicionarnoticia').style.display = 'block' " >ADICIONAR </a>

<!-- DIVS de CONTROLO -->
<!-- ADICIONAR NOTICIA -->
<div id='adicionarnoticia' style='display: none; position: absolute;  border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; font-size: 12px; width: 500px; z-index:100;'>
<iframe src="adicionar_noticia.php" name="adicionarnoticias" frameborder="0" width="500px" height="370px"></iframe>
<br />
<div style='text-align: right;'><a onmouseover='this.style.cursor="pointer" ' style='font-size: 12px;' onfocus='this.blur();' href="home.php"><!--onclick="document.getElementById('PopUp').style.display = 'none' "--><span style="text-decoration: underline;">Fechar janela</span></a></div>
</div>

<!-- EDITAR NOTICIA -->
<div id='editarnoticia' style='display: none; position: absolute;  border: solid black 1px; padding: 10px; background-color: rgb(255,255,225); text-align: justify; font-size: 12px; width: 500px; z-index:100;'>
<?php echo '<iframe src="editar_noticia.php?id='.$id_actual.'" name="adicionarnoticias" frameborder="0" width="500px" height="370px"></iframe>'; ?>
<br />
<div style='text-align: right;'><a onmouseover='this.style.cursor="pointer" ' style='font-size: 12px;' onfocus='this.blur();' href="home.php"><!--onclick="document.getElementById('PopUp').style.display = 'none' "--><span style="text-decoration: underline;">Fechar janela</span></a></div>
</div>



			<h1>Listagem de notícias</h1>
			<div class="breadcrumbs"><a href="#">Geral</a> / <a href="#">Listagem</a></div>
		</div><br />
	  <div class="select-bar">
	    <label>
	    <input type="text" name="textfield" />
	    </label>
	    <label>
		<input type="submit" name="Submit" value="Procurar" />
		</label>
	  </div>
		<div class="table">
			<img src="img/bg-th-left.gif" width="8" height="7" alt="" class="left" />
			<img src="img/bg-th-right.gif" width="7" height="7" alt="" class="right" />
			<table class="listing" cellpadding="0" cellspacing="0">
				<tr>
					<th class="first" width="177">Título</th>
					<th>URL</th>
					<th>Miniatura</th>
					<th>Data</th>
					<th>Descrição</th>
					<!--<th>Head</th>
					<th>Header</th>-->
					<th class="last">Funções</th>
				</tr>
<?php

$par = 0;

$sql = mysql_query("SELECT ID FROM tv_noticias ORDER BY date");
	for ($pass = 0; $pass < mysql_num_rows($sql); $pass++){

		$par++;
		if ($par % 2 == 0) {
		echo '<tr>';
		$query = mysql_query("SELECT title FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td class="first style1">'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT url FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT thumbnail FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td><a href="'.mysql_result($query, 0).'" target="_blank" rel="lightbox"><strong>Ver</strong></a></td>';
		$query = mysql_query("SELECT date FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT description FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';

				$query = mysql_query("SELECT ID FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
				$id_actual = mysql_result($query, 0);
			echo '<td class="last"><a href="#" onmouseover=\'this.style.cursor="pointer" \' onfocus=\'this.blur();\' onclick="document.getElementById(\'editarnoticia\').style.display = \'block\' "><img src="img/edit-icon.gif"></a> <a href="javascript:popUp(\'eliminar_noticia.php?id='.$id_actual.'\')"><img src="img/del-icon.gif"></a></td>';
			echo '</tr>';
			} else {
			echo '<tr class="bg">';
		$query = mysql_query("SELECT title FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td class="first style1">'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT url FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT thumbnail FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td><a href="'.mysql_result($query, 0).'" target="_blank" rel="lightbox"><strong>Ver</strong></a></td>';
		$query = mysql_query("SELECT date FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';
		$query = mysql_query("SELECT description FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
			echo '<td>'.mysql_result($query, 0).'</td>';
				$query = mysql_query("SELECT ID FROM tv_noticias WHERE ID = ".mysql_result($sql, $pass)." LIMIT 1");	
				$id_actual = mysql_result($query, 0);
			echo '<td class="last"><a href="#" onmouseover=\'this.style.cursor="pointer" \' onfocus=\'this.blur();\' onclick="document.getElementById(\'editarnoticia\').style.display = \'block\' "><img src="img/edit-icon.gif"></a> <a href="javascript:popUp(\'eliminar_noticia.php?id='.$id_actual.'\')"><img src="img/del-icon.gif"></a></td>';
			echo '</tr>';
			}
					}
					?>



			</table>

No entanto, gostaria de saber como é que, sem mudar de página, por GET consigo ir buscar o valor para uma iframe, que está na DIV editarnoticia.

O código da iframe da DIV editarnoticia:

<?php

$id = $_GET['id'];

$sql = mysql_query("SELECT * FROM tv_noticias ORDER BY date WHERE ID = $id");

while ($row = mysql_fetch_assoc($sql)) {

echo '<font face="Verdana" size="2px">';
echo '<form action="editar_noticia2.php" method="POST">';
    echo '<p class="a">URL da miniatura:<br />';
    echo '<input type="text" name="thumbnail" size="75" maxlength="70" value="'.$row['thumbnail'].'" />';
    echo '</h1>';
    echo '<p class="a">Título:<br />';
    echo '<input type="text" name="title" size="55"  maxlength="50" value="'.$row['title'].'" />';
    echo '</p>';
    echo '<p class="a">Descrição:<br />';
    echo '<textarea rows="1" cols="55" name="description" onkeypress="return imposeMaxLength(this, 45);" value="'.$row['description'].'" ></textarea>';
    echo '</p>';
    echo '<p class="a">Data:<br />';
    echo '<input type="text" name="date" size="16" value="'.$row['thumbnail'].'" />';
    echo '</p>';
    echo '<p class="a">URL do Youtube:<br />';
    echo '<input type="text" name="url" size="75" maxlength="70" value="'.$row['url'].'" />';
    echo '</p>';
    echo '<br />';
    echo '<input type="submit" value="Editar notícia" />  <input type="reset" value="Apagar" />';
    echo '</form>';
echo '</font>';

}

?>

Mas vai-me dar erro porque como não considera o insert da iframe como mudança de página, não vai ler o GET...

Sugestões? Não sei se fui bem explicíto...  😳

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.