limite post annunci a utente ...

searedone

Utente Attivo
11 Giu 2010
508
0
0
ho provato così ma il limite non funziona... :(

chi mi può' aiutare ????

PHP:
<?php echo $_SESSION['user_id'];  

require ("db_connect.php");   

 

if (isset($_POST['descrizione'])):   
  // x un nuovo annuncio usa il form  
    

 $user_id = $_POST['user_id'];  

  $aid = $_POST['aid'];  
  $cid = $_POST['cid'];  
  $did = $_POST['did'];  
   $eid = $_POST['eid'];  
    $fid = $_POST['fid'];  
    $gid = $_POST['gid']; 
     $zid = $_POST['zid']; 
  $descrizione=$_POST["descrizione"];
$descrizione=ereg_replace("\n","<br>",$descrizione); 
  $mq = $_POST['mq'];  
   $via = $_POST['via'];  
  $locali = $_POST['locali'];  
  $prezzo = $_POST['prezzo'];  
  $tipologia = $_POST['tipologia'];  
  $altro = $_POST['altro'];  
  $cats = $_POST['cats'];  
  
  
 $nome_file_temporaneo = $_FILES['file_inviato']['tmp_name'];
    $nome_file_vero = $_FILES['file_inviato']['name'];
    $tipo_file = $_FILES['file_inviato']['type'];
    $dati_file = file_get_contents($nome_file_temporaneo);
    $dati_file = addslashes($dati_file);
    
     $nome_file_temporaneo2 = $_FILES['file_inviato2']['tmp_name'];
    $nome_file_vero2 = $_FILES['file_inviato2']['name'];
    $tipo_file2 = $_FILES['file_inviato2']['type'];
    $dati_file2 = file_get_contents($nome_file_temporaneo2);
    $dati_file2 = addslashes($dati_file2);
  
  
   $nome_file_temporaneo3 = $_FILES['file_inviato3']['tmp_name'];
    $nome_file_vero3 = $_FILES['file_inviato3']['name'];
    $tipo_file3 = $_FILES['file_inviato3']['type'];
    $dati_file3 = file_get_contents($nome_file_temporaneo3);
    $dati_file3 = addslashes($dati_file3);
    
     $nome_file_temporaneo4 = $_FILES['file_inviato4']['tmp_name'];
    $nome_file_vero4 = $_FILES['file_inviato4']['name'];
    $tipo_file4 = $_FILES['file_inviato4']['type'];
    $dati_file4 = file_get_contents($nome_file_temporaneo4);
    $dati_file4 = addslashes($dati_file4);


 $nome_file_temporaneo5 = $_FILES['file_inviato5']['tmp_name'];
    $nome_file_vero5 = $_FILES['file_inviato5']['name'];
    $tipo_file5 = $_FILES['file_inviato5']['type'];
    $dati_file5 = file_get_contents($nome_file_temporaneo5);
    $dati_file5 = addslashes($dati_file5);
    
$nome_file_temporaneo10 = $_FILES['file_inviato10']['tmp_name'];
    $nome_file_vero10 = $_FILES['file_inviato10']['name'];
    $tipo_file10 = $_FILES['file_inviato10']['type'];
    $dati_file10 = file_get_contents($nome_file_temporaneo10);
    $dati_file10 = addslashes($dati_file10);    
    
    if(get_magic_quotes_gpc()) { 
    
    $descrizione=stripslashes($descrizione);

}  

$descrizione =mysql_real_escape_string($descrizione); 

  if ($aid == '') {  
    exit('<p>Scegli la provincia x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($cid == '') {  
    exit('<p>Scegli il comune x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($did == '') {  
    exit('<p>Scegli la regione x l annuncio. Click "Back" and try again.</p>');  
  } 

if ($eid == '') {  
    exit('<p>Scegli il tipo cliente x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($fid == '') {  
    exit('<p>Scegli il canale dell annuncio. Click "Back" and try again.</p>');  
  } 


if ($gid == '') {  
    exit('<p>Scegli le condizioni dell immobile. Click "Back" and try again.</p>');  
  } 
  
  if ($zid == '') {  
    exit('<p>Scegli lo stato dell annuncio. Click "Back" and try again.</p>');  
  } 



  $sql = "INSERT INTO annunci SET  
      descrizione='$descrizione',  
      mq='$mq',  
      locali='$locali',  
      prezzo='$prezzo',  
      tipologia='$tipologia',  
      altro='$altro', 
      via='$via', 
     
      provinciaid='$aid',  
      cittaid='$cid',  
      regioneid='$did',  
      clienteid='$eid',  
       tipoid='$fid',  
       condizioniid='$gid',
       statoid='$zid',  
       nome_file = '$nome_file_vero', 
                tipo_file = '$tipo_file', 
                dati_file = '$dati_file', 
                
                nome_file2 = '$nome_file_vero2', 
                tipo_file2 = '$tipo_file2', 
                dati_file2 = '$dati_file2', 
                
                nome_file3 = '$nome_file_vero3', 
                tipo_file3 = '$tipo_file3', 
                dati_file3 = '$dati_file3', 
                
                nome_file4 = '$nome_file_vero4', 
                tipo_file4 = '$tipo_file4', 
                dati_file4 = '$dati_file4', 
                
                nome_file5 = '$nome_file_vero5', 
                tipo_file5 = '$tipo_file5', 
                dati_file5 = '$dati_file5', 
                
                nome_file10 = '$nome_file_vero10', 
                tipo_file10 = '$tipo_file10', 
                dati_file10 = '$dati_file10', 
        
      user_id=".$_SESSION['user_id']."";
  if (@mysql_query($sql)) {
    echo '<p></p>';
  } else {
    exit('<p>Errore aggiunta nuovo annuncio: ' . mysql_error() . '</p>');
  }
  
  $quanti=mysql_num_rows(mysql_query($sql));//guardi quanti annunci ha 
//ho messo per esempio 10 
if($quanti <= 10){ 
    //inserisci l'annuncio 
}else{ 
    echo "hai gia inserito 10 annunci, non puoi inserirne altri"; 

}
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
hai messo l'insert fuori dalla if che verifica il numero
non hai messo la query di ricerca
hai messo il nome della query di insert in mysql_num_rows


PHP:
<?php
//....
  $sql_c="SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND attivo='A'";
  $quanti=mysql_num_rows(mysql_query($sql_c));//guardi quanti annunci ha attivi  
//ho messo per esempio 10  
if($quanti <= 10){  
    //inserisci l'annuncio se non già inseriti 10
	//guarda che non devi scrivere due volte l'inserimento, quello fuori dell'if va tolto
	if (@mysql_query($sql)) { 
		echo '<p></p>'; 
	}else{ 
		exit('<p>Errore aggiunta nuovo annuncio: ' . mysql_error() . '</p>'); 
	}
}else{  
    //altrimenti avvisi che non può inserirne più
	echo "hai gia inserito 10 annunci, non puoi inserirne altri";  
}
//.....
?>
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
mhhhhhhhhhh scusa l'ignoranza ma non capisco dove devo mettere questo benedetto if :( ......

Alcune volte faccio cose impossibili e il più delle volte mi perdo in un bicchiere d'acqua :( :(

PHP:
<?php echo $_SESSION['user_id'];  

require ("db_connect.php");   

 

if (isset($_POST['descrizione'])):   
  // x un nuovo annuncio usa il form  
    

 $user_id = $_POST['user_id'];  

  $aid = $_POST['aid'];  
  $cid = $_POST['cid'];  
  $did = $_POST['did'];  
   $eid = $_POST['eid'];  
    $fid = $_POST['fid'];  
    $gid = $_POST['gid'];  
  $descrizione=$_POST["descrizione"];
$descrizione=ereg_replace("\n","<br>",$descrizione); 
  $mq = $_POST['mq'];  
   $via = $_POST['via'];  
  $locali = $_POST['locali'];  
  $prezzo = $_POST['prezzo'];  
  $tipologia = $_POST['tipologia'];  
  $altro = $_POST['altro'];  
  $cats = $_POST['cats'];  
  
  
 $nome_file_temporaneo = $_FILES['file_inviato']['tmp_name'];
	$nome_file_vero = $_FILES['file_inviato']['name'];
	$tipo_file = $_FILES['file_inviato']['type'];
	$dati_file = file_get_contents($nome_file_temporaneo);
	$dati_file = addslashes($dati_file);
	
	 $nome_file_temporaneo2 = $_FILES['file_inviato2']['tmp_name'];
	$nome_file_vero2 = $_FILES['file_inviato2']['name'];
	$tipo_file2 = $_FILES['file_inviato2']['type'];
	$dati_file2 = file_get_contents($nome_file_temporaneo2);
	$dati_file2 = addslashes($dati_file2);
  
  
   $nome_file_temporaneo3 = $_FILES['file_inviato3']['tmp_name'];
	$nome_file_vero3 = $_FILES['file_inviato3']['name'];
	$tipo_file3 = $_FILES['file_inviato3']['type'];
	$dati_file3 = file_get_contents($nome_file_temporaneo3);
	$dati_file3 = addslashes($dati_file3);
	
	 $nome_file_temporaneo4 = $_FILES['file_inviato4']['tmp_name'];
	$nome_file_vero4 = $_FILES['file_inviato4']['name'];
	$tipo_file4 = $_FILES['file_inviato4']['type'];
	$dati_file4 = file_get_contents($nome_file_temporaneo4);
	$dati_file4 = addslashes($dati_file4);


 $nome_file_temporaneo5 = $_FILES['file_inviato5']['tmp_name'];
	$nome_file_vero5 = $_FILES['file_inviato5']['name'];
	$tipo_file5 = $_FILES['file_inviato5']['type'];
	$dati_file5 = file_get_contents($nome_file_temporaneo5);
	$dati_file5 = addslashes($dati_file5);
	
	if(get_magic_quotes_gpc()) { 
	
	$descrizione=stripslashes($descrizione);

}  

$descrizione =mysql_real_escape_string($descrizione); 

  if ($aid == '') {  
    exit('<p>Scegli la provincia x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($cid == '') {  
    exit('<p>Scegli il comune x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($did == '') {  
    exit('<p>Scegli la regione x l annuncio. Click "Back" and try again.</p>');  
  } 

if ($eid == '') {  
    exit('<p>Scegli il tipo cliente x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($fid == '') {  
    exit('<p>Scegli il canale dell annuncio. Click "Back" and try again.</p>');  
  } 


if ($gid == '') {  
    exit('<p>Scegli le condizioni dell immobile. Click "Back" and try again.</p>');  
  } 



  $sql = "INSERT INTO annunci SET  
      descrizione='$descrizione',  
      mq='$mq',  
      locali='$locali',  
      prezzo='$prezzo',  
      tipologia='$tipologia',  
      altro='$altro', 
      via='$via', 
     
      provinciaid='$aid',  
      cittaid='$cid',  
      regioneid='$did',  
      clienteid='$eid',  
       tipoid='$fid',  
       condizioniid='$gid',
       nome_file = '$nome_file_vero', 
				tipo_file = '$tipo_file', 
				dati_file = '$dati_file', 
				
				nome_file2 = '$nome_file_vero2', 
				tipo_file2 = '$tipo_file2', 
				dati_file2 = '$dati_file2', 
				
				nome_file3 = '$nome_file_vero3', 
				tipo_file3 = '$tipo_file3', 
				dati_file3 = '$dati_file3', 
				
				nome_file4 = '$nome_file_vero4', 
				tipo_file4 = '$tipo_file4', 
				dati_file4 = '$dati_file4', 
				
				nome_file5 = '$nome_file_vero5', 
				tipo_file5 = '$tipo_file5', 
				dati_file5 = '$dati_file5', 
        
      user_id=".$_SESSION['user_id']."";
  if (@mysql_query($sql)) {
    echo '<p></p>';
  } else {
    exit('<p>Errore aggiunta nuovo annuncio: ' . mysql_error() . '</p>');
  }
 
  $jid = mysql_insert_id();

  if (isset($_POST['cats'])) {
    $cats = $_POST['cats'];
  } else {
    $cats = array();
  }

  $numCats = 0;
  foreach ($cats as $catID) {
    $sql = "INSERT IGNORE INTO cittaprovinciauser
            SET annunciid=$jid, cittaid=$catID, regioneid=$catID,  clienteid=$catID, tipoid=catID, condizioniid=catID ";
    $ok = @mysql_query($sql);
    if ($ok) {
      $numCats = $numCats + 1;
    } else {
      echo "<p>Errore inserimento annuncio $catID: " .
          mysql_error() . '</p>';
    }
  
  }
  ?>
  
 
<p>Annuncio salvato correttamente <?php echo $Cats; ?> categories.</p>

<p><a href="<?php echo $_SERVER['PHP_SELF']; ?>"></a></p>
<p><a href="submit.php"><img src="immagini/continua.gif"/></a></p>

<?php
else: // inserimento provincia e citta'

  $authors = @mysql_query('SELECT id, name FROM provincia');
  if (!$authors) {
    exit('<p>errore inserimento provincia.</p>');
  }

  $cats = @mysql_query('SELECT id, citta FROM citta');
  if (!$cats) {
    exit('<p>errore inserimento citta.</p>');
  }
  
  $regiones = @mysql_query('SELECT id, regione FROM regione');
  if (!$regiones) {
    exit('<p>errore inserimento citta.</p>');
  }
  
  $clientes = @mysql_query('SELECT id, cliente FROM cliente');
  if (!$clientes) {
    exit('<p>errore inserimento citta.</p>');
  }
  
  $tipos = @mysql_query('SELECT id, tipo FROM tipo');
  if (!$tipos) {
    exit('<p>errore inserimento citta.</p>');
  }
  
  $condizionis = @mysql_query('SELECT id, condizioni FROM condizioni');
  if (!$condizionis) {
    exit('<p>errore inserimento citta.</p>');
  }
  
 
?>
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
devi metterlo in modo che se gli annunci sono più di 10 non faccia l'insert e avvisi
PHP:
 <?php
 //....tutto quello che c'è prima
$sql = "INSERT INTO annunci SET   
      descrizione='$descrizione',   
      mq='$mq',   
      locali='$locali',   
      prezzo='$prezzo',   
      tipologia='$tipologia',   
      altro='$altro',  
      via='$via',  
      provinciaid='$aid',   
      cittaid='$cid',   
      regioneid='$did',   
      clienteid='$eid',   
      tipoid='$fid',   
      condizioniid='$gid', 
      nome_file = '$nome_file_vero',  
      tipo_file = '$tipo_file',  
      dati_file = '$dati_file',           
      nome_file2 = '$nome_file_vero2',  
      tipo_file2 = '$tipo_file2',  
      dati_file2 = '$dati_file2',            
      nome_file3 = '$nome_file_vero3',  
      tipo_file3 = '$tipo_file3',  
      dati_file3 = '$dati_file3',           
      nome_file4 = '$nome_file_vero4',  
      tipo_file4 = '$tipo_file4',  
      dati_file4 = '$dati_file4',  
      nome_file5 = '$nome_file_vero5',  
      tipo_file5 = '$tipo_file5',  
      dati_file5 = '$dati_file5',  
      user_id=".$_SESSION['user_id']."";

//la querry che cerca il numero
$sql_c="SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND attivo='A'"; 
$quanti=mysql_num_rows(mysql_query($sql_c));//guardi quanti annunci ha attivi   
//ho messo per esempio 10   
if($quanti <= 10){//inizio dell if else numero annunci inseriti 
	//meno di 10 inserisco
	if (@mysql_query($sql)) { //query di insert
		echo '<p></p>'; 
	} else { 
		exit('<p>Errore aggiunta nuovo annuncio: ' . mysql_error() . '</p>'); 
	} 
	$jid = mysql_insert_id(); 
}else{
  //più di 10 non inserisco
  echo "hai inserito più di 10 annunci";
}//fine dell'if else più di 10 annunci
//......tutto qello che viene dopo
?>

p.s.
verifica che non abbia fatto errori con il copia/incolla
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
Grazie mille borgooooo,
Sempre gentilissimooooooooooooooo ;) ,,,,

Ho pRoblemi con la linea Internet e con iPad faccio fatica------ ... Appena posso provoooo,,
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
Ciao Borgo,
chiedo venia non ti ho ancora risposto perchè sto aspettando un traslocco di linea che non arriva... appena posso che riesco a recuperare la pagina degli annunci provo e ti dico se funziona ... :(

mi sento perso senza connessione ......

Ps nel caso vedo se riesco a scroccarla in questi giorni :)
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
ciao Borgo,
ho provato così, ma mi posta annunci oltre i 10 :(

PHP:
<?php echo $_SESSION['user_id'];  

require ("db_connect.php");   

 

if (isset($_POST['descrizione'])):   
  // x un nuovo annuncio usa il form  
    

 $user_id = $_POST['user_id'];  

  $aid = $_POST['aid'];  
  $cid = $_POST['cid'];  
  $did = $_POST['did'];  
   $eid = $_POST['eid'];  
    $fid = $_POST['fid'];  
    $gid = $_POST['gid'];  
  $descrizione=$_POST["descrizione"];
$descrizione=ereg_replace("\n","<br>",$descrizione); 
  $mq = $_POST['mq'];  
   $via = $_POST['via'];  
  $locali = $_POST['locali'];  
  $prezzo = $_POST['prezzo'];  
  $tipologia = $_POST['tipologia'];  
  $altro = $_POST['altro'];  
  $cats = $_POST['cats'];  
  
  
 $nome_file_temporaneo = $_FILES['file_inviato']['tmp_name'];
	$nome_file_vero = $_FILES['file_inviato']['name'];
	$tipo_file = $_FILES['file_inviato']['type'];
	$dati_file = file_get_contents($nome_file_temporaneo);
	$dati_file = addslashes($dati_file);
	
	 $nome_file_temporaneo2 = $_FILES['file_inviato2']['tmp_name'];
	$nome_file_vero2 = $_FILES['file_inviato2']['name'];
	$tipo_file2 = $_FILES['file_inviato2']['type'];
	$dati_file2 = file_get_contents($nome_file_temporaneo2);
	$dati_file2 = addslashes($dati_file2);
  
  
   $nome_file_temporaneo3 = $_FILES['file_inviato3']['tmp_name'];
	$nome_file_vero3 = $_FILES['file_inviato3']['name'];
	$tipo_file3 = $_FILES['file_inviato3']['type'];
	$dati_file3 = file_get_contents($nome_file_temporaneo3);
	$dati_file3 = addslashes($dati_file3);
	
	 $nome_file_temporaneo4 = $_FILES['file_inviato4']['tmp_name'];
	$nome_file_vero4 = $_FILES['file_inviato4']['name'];
	$tipo_file4 = $_FILES['file_inviato4']['type'];
	$dati_file4 = file_get_contents($nome_file_temporaneo4);
	$dati_file4 = addslashes($dati_file4);


 $nome_file_temporaneo5 = $_FILES['file_inviato5']['tmp_name'];
	$nome_file_vero5 = $_FILES['file_inviato5']['name'];
	$tipo_file5 = $_FILES['file_inviato5']['type'];
	$dati_file5 = file_get_contents($nome_file_temporaneo5);
	$dati_file5 = addslashes($dati_file5);
	
	if(get_magic_quotes_gpc()) { 
	
	$descrizione=stripslashes($descrizione);

}  

$descrizione =mysql_real_escape_string($descrizione); 

  if ($aid == '') {  
    exit('<p>Scegli la provincia x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($cid == '') {  
    exit('<p>Scegli il comune x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($did == '') {  
    exit('<p>Scegli la regione x l annuncio. Click "Back" and try again.</p>');  
  } 

if ($eid == '') {  
    exit('<p>Scegli il tipo cliente x l annuncio. Click "Back" and try again.</p>');  
  } 
  
  if ($fid == '') {  
    exit('<p>Scegli il canale dell annuncio. Click "Back" and try again.</p>');  
  } 


if ($gid == '') {  
    exit('<p>Scegli le condizioni dell immobile. Click "Back" and try again.</p>');  
  } 



  $sql = "INSERT INTO annunci SET    
      descrizione='$descrizione',    
      mq='$mq',    
      locali='$locali',    
      prezzo='$prezzo',    
      tipologia='$tipologia',    
      altro='$altro',   
      via='$via',   
      provinciaid='$aid',    
      cittaid='$cid',    
      regioneid='$did',    
      clienteid='$eid',    
      tipoid='$fid',    
      condizioniid='$gid',  
      nome_file = '$nome_file_vero',   
      tipo_file = '$tipo_file',   
      dati_file = '$dati_file',            
      nome_file2 = '$nome_file_vero2',   
      tipo_file2 = '$tipo_file2',   
      dati_file2 = '$dati_file2',             
      nome_file3 = '$nome_file_vero3',   
      tipo_file3 = '$tipo_file3',   
      dati_file3 = '$dati_file3',            
      nome_file4 = '$nome_file_vero4',   
      tipo_file4 = '$tipo_file4',   
      dati_file4 = '$dati_file4',   
      nome_file5 = '$nome_file_vero5',   
      tipo_file5 = '$tipo_file5',   
      dati_file5 = '$dati_file5',   
      user_id=".$_SESSION['user_id'].""; 

//la querry che cerca il numero 
$sql_c="SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND stato='attivo'";  
$quanti=mysql_num_rows(mysql_query($sql_c));//guardi quanti annunci ha attivi    
//ho messo per esempio 10    
if($quanti <= 10){//inizio dell if else numero annunci inseriti  
    //meno di 10 inserisco 
    if (@mysql_query($sql)) { //query di insert 
        echo '<p></p>';  
    } else {  
        exit('<p>Errore aggiunta nuovo annuncio: ' . mysql_error() . '</p>');  
    }  
    $jid = mysql_insert_id();  
}else{ 
  //più di 10 non inserisco 
  echo "hai inserito più di 10 annunci"; 
}//fine dell'if else più di 10 annunci 
//......tutto qello che viene dopo 
 
  $jid = mysql_insert_id();

  if (isset($_POST['cats'])) {
    $cats = $_POST['cats'];
  } else {
    $cats = array();
  }

  $numCats = 0;
  foreach ($cats as $catID) {
    $sql = "INSERT IGNORE INTO cittaprovinciauser
            SET annunciid=$jid, cittaid=$catID, regioneid=$catID,  clienteid=$catID, tipoid=catID, condizioniid=catID ";
    $ok = @mysql_query($sql);
    if ($ok) {
      $numCats = $numCats + 1;
    } else {
      echo "<p>Errore inserimento annuncio $catID: " .
          mysql_error() . '</p>';
    }
  
  }
  ?>
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
prova a mettere un paio di var_dump e dimmi cosa ti restituisce

PHP:
<?php
//......
//la querry che cerca il numero  
$sql_c="SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND stato='attivo'"; 
var_dump($sql_c);  
$quanti=mysql_num_rows(mysql_query($sql_c));//guardi quanti annunci ha attivi     
var_dump($quanti);
//ho messo per esempio 10     

//.......
?>
poi un piccolo dubbio nel where della $sql_c:
per stato attivo non avevi messo attivo='A'? hai cambiato? e sei hai cambiato hai cambiato il campo (nome e contenuto) anche nella tabella?
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
mi restituisce questo

55string(59) "SELECT * FROM annunci WHERE user_id='55' AND stato='attivo'" NULL

poi un piccolo dubbio nel where della $sql_c:
per stato attivo non avevi messo attivo='A'? hai cambiato? e sei hai cambiato hai cambiato il campo (nome e contenuto) anche nella tabella?

nella tabella gli annunci attivi li prendo dalla tabella stato attivo
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
quel NULL sta a significare che la query non va a buon fine
separa la query
PHP:
//...... 
//la querry che cerca il numero   
$sql_c="SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND stato='attivo'";  
var_dump($sql_c);   
$result=mysql_query($sql_c);
var_dump($result);//se ti ta bool FALSE c'è qualcosa che non va nella quary di ricerca posta eventualmente la struttura della tabella annunci
$quanti=mysql_num_rows($result);//guardi quanti annunci ha attivi
var_dump($quanti); 
//ho messo per esempio 10      

//....... 
?>
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
cosi mi da' questo :

55string(59) "SELECT * FROM annunci WHERE user_id='55' AND stato='attivo'" bool(false) NULL
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
allora non si scappa, l'errore che stai facendo è nella querry
SELECT * FROM annunci WHERE user_id='".$_SESSION['user_id']."' AND stato='attivo'"
l'errore può essere o nei nomi dei campi o nel tipo di vaolri che assegni
posta la struttura della tabella annunci
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
Ciao ...


Ti posto la tabella annunci :

PHP:
CREATE TABLE IF NOT EXISTS `annunci` (
  `id_annunci` int(11) NOT NULL AUTO_INCREMENT,
  `descrizione` longtext NOT NULL,
  `mq` varchar(255) NOT NULL,
  `locali` varchar(255) NOT NULL,
  `prezzo` varchar(255) NOT NULL,
  `tipologia` varchar(255) NOT NULL,
  `altro` varchar(255) NOT NULL,
  `via` varchar(255) NOT NULL,
  `timesviewed` int(11) NOT NULL,
  `nome_file` varchar(255) NOT NULL,
  `tipo_file` varchar(255) NOT NULL,
  `dati_file` longblob NOT NULL,
  `nome_file2` varchar(200) NOT NULL,
  `tipo_file2` varchar(255) NOT NULL,
  `dati_file2` longblob NOT NULL,
  `nome_file3` varchar(255) NOT NULL,
  `tipo_file3` varchar(255) NOT NULL,
  `dati_file3` longblob NOT NULL,
  `nome_file4` varchar(255) NOT NULL,
  `tipo_file4` varchar(255) NOT NULL,
  `dati_file4` longblob NOT NULL,
  `nome_file5` varchar(255) NOT NULL,
  `tipo_file5` varchar(255) NOT NULL,
  `dati_file5` longblob NOT NULL,
  `nome_file10` varchar(255) NOT NULL,
  `tipo_file10` varchar(255) NOT NULL,
  `dati_file10` longblob NOT NULL,
  `ts` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `provinciaid` int(255) NOT NULL,
  `user_id` int(11) NOT NULL,
  `cittaid` int(11) NOT NULL,
  `regioneid` int(11) NOT NULL,
  `clienteid` int(11) NOT NULL,
  `tipoid` int(11) NOT NULL,
  `condizioniid` int(11) NOT NULL,
  `id_image` int(5) NOT NULL,
  `click_annuncio` int(11) NOT NULL,
  `statoid` int(11) NOT NULL,
  PRIMARY KEY (`id_annunci`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=243 ;
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
infatti nella tabella non esiste un campo chiamato stato e che, mi sembra, abbia i valori che ti servono
vedo un campo chiamato `statoid` int(11) NOT NULL, ma mi sembra che non c'entri nulla sul fatto che un annuncio sia attivo o no,
per forza la query ti da false e inserisce c&p
se non vuoi mettere un campo enum aggiungi alla fina un campo
'stato' varchar(1) NOT NULL, default 'A'
cioè l'annuncio è attivo e quindi la query lo conteggerà
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
hai ragione...

ma io con stato id richiamo la tabella

PHP:
CREATE TABLE IF NOT EXISTS `stato` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `stato` varchar(100) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

--
-- Dump dei dati per la tabella `stato`
--

INSERT INTO `stato` (`id`, `stato`) VALUES
(1, 'attivo'),
(2, 'sospeso');

E poi con la join richiamo solo gli annunci attivi .. !

PHP:
  $obj_id = @mysql_query(
"SELECT * FROM
    annunci INNER JOIN regione ON (annunci.regioneid=regione.id AND provinciaid=provinciaid )
     INNER JOIN provincia ON (annunci.provinciaid=provincia.id)
     INNER JOIN citta ON (annunci.cittaid=citta.id)
	  INNER JOIN cliente ON (annunci.clienteid=cliente.id)
	  INNER JOIN stato ON (annunci.statoid=stato.id)
    
     
WHERE
    provincia.name='agrigento' AND stato.stato='attivo' ORDER BY `id_annunci` DESC LIMIT ".$inizio.",".$max) or die (mysql_error());
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
mi hai cambiato le carte in tavola, non avevi mai parlato di unanuova tabella, che comunque ad occhio e croce non può fare quello che ti serve (ma può darsi che mi sbagli)
secondo me ti stai complicando la vita per non aggiungere il campo 'stato' alla tabella annunci
 

searedone

Utente Attivo
11 Giu 2010
508
0
0
MH :(

era solo per semplificarmi la vita con la join .. e poi se ti ricordi non mi prendeva il campo enum :(
 
Discussioni simili
Autore Titolo Forum Risposte Data
ges Microsoft ACCESS oltre ogni limite (tre manuali) Altri Annunci 2
M [PHP] Imposta limite giornaliero PHP 1
P [Java] limite destro di un JFrame Java 5
L php - limite di memoria PHP 1
Z Limite invio newsletter con PHP - mail() PHP 4
Shyson [WordPress] Mettere un limite a lunghezza caratteri WordPress 11
ecosito Limite di 1 tweet sul Plugin di Twitter Javascript 2
L Limite lunghezza $_POST ??? PHP 1
G Limite di "grandezza" per cui non conviene più Joomla Joomla 5
Monital Query oltre il limite massimo PHP 4
Mauro Guardiani cerco webmaster per problemi reCAPTCHA e limite indirizzo ip. Offerte e Richieste di Lavoro e/o Collaborazione 0
A Limite minimo con countdown textarea Javascript 0
X interazione javascript e php (aggirare limite) Javascript 2
A Ciclo for su 2 colonne con limite a 10 PHP 1
M Limite massimo foto in Mooflow? Javascript 0
B Limite ai login PHP 13
I Limite di peso del file in un upload di file in flash Flash 1
I Limite Recordset in update database Classic ASP 2
L limite altezza in scrollpane Flash 1
amanu86 Limite Access MS Access 1
C limite tempo script Classic ASP 2
S passare un valore da un form a un file .php con metodo post PHP 4
D [COMPRO/CERCO] GUEST POST o scambio link per sito di Spiritualità ed Esoterismo. Vendere e Acquistare pubblicita' online 0
J [Vendo] Guest post a fini Posizionamento organico Vendere e Acquistare pubblicita' online 0
T [VENDO] Guest Post su siti di Proprietà Offerte e Richieste di scambio links 0
T [VENDO] Guest Post su siti di Proprietà Vendere e Acquistare pubblicita' online 0
A Vendo Guest post Offerte e Richieste di scambio links 0
T [VENDO] Guest Post su siti di Proprietà con IP diversi Offerte e Richieste di scambio links 0
T Segnalazione post PHP 4
P inserire due voci in un titolo post wp WordPress 1
S Variabile in post su altra pagina PHP 2
A recuperare i dati passati nel post PHP 1
R [C#] Scrivere un post in grassetto con Selenium su FB Mobile .NET Framework 0
T Vendo Guest Post Offerte e Richieste di Lavoro e/o Collaborazione 1
G cerco: traffico sito, pubblicità condividente post su pagine gruppi Vendere e Acquistare pubblicita' online 0
R Distribuire uno Script "Facebook Auto Post" PHP 0
D VENDO Guest Post ZA 45 su sito dedicato agli influencer italiani Vendere e Acquistare pubblicita' online 0
D [VENDO] Guest Post/Banner su sito Offerte e Richieste di scambio links 0
R [C#] Automatizzare un inserimento di un Post su un Gruppo Facebook .NET Framework 0
MarcoGrazia Se non sai se riceverai da GET o da POST, puoi verificarlo e far scegliere allo script. Snippet PHP 0
A php metodo post jquery non da mai errore jQuery 4
Fendo59 Passare parametri con metodo POST a una pagina in un frame PHP 0
T [VENDO] Guest post su 16 siti ZA 39 Vendere e Acquistare pubblicita' online 0
F Post [VENDO] articoli in vari siti tematici e testate giornalistiche Vendere e Acquistare pubblicita' online 0
moustache text box + post php con IE si comporta in modo strano PHP 16
L Richieste HTTP get post PHP 1
G Passare path directory in POST PHP 2
S come togliere un post dai risultati di google? Supporto Mr.Webmaster 5
Web93 CAMBIARE TAG POST TITOLO DA H2 A H1 WordPress 1
S (VENDO) Guest post Vendere e Acquistare pubblicita' online 0

Discussioni simili