MRW.it Forum
  • Home
  • Forum
  • Fare Web
  • PHP

[PHP] Ricerca record tramite post

  • Creatore Discussione Creatore Discussione ONE313
  • Data di inizio Data di inizio 4 Ott 2018
O

ONE313

Utente Attivo
10 Set 2016
37
2
8
  • 4 Ott 2018
  • #1
Buona sera, ho un problema nel visualizzare il risultato di due tabelle relazonate tra loro, utilizzando anche un select box. Volevo fare una ricerca come siti subito,amazon tramite categoria o prodotto.

PHP:
?php

$Host = "localhost";
$User = "root";
$Pass = "";
$Db = "ricerca_select";

$Conn = mysqli_connect($Host, $User, $Pass, $Db);

if (isset($_POST["submit"])) {
    $citta=$_POST["citta"];

$Query = "SELECT nome,cognome,citta FROM utente,citta where utente.ks_citta=citta.id_citta
  " ;
    /*oppure citta='$Citta' in base se volgio cercarea
    attraverso l'id o la cittas*/

    $Result= mysqli_query($Conn,$Query);

while ($Row=mysqli_fetch_array($Result)) {
   
        echo $Row[0]." ".$Row[1]." ".$Row[2]."<br>";
}
}
?>

HTML:
<!DOCTYPE html>
<html>
<head>
    <title>prova</title>
</head>
<body>
<form action="#" method="POST">
    <select>
        <option name="citta">roma</option>
        <option name="citta">parigi</option>
    </select>
    <input type="text" name="citta">
<input type="submit" name="submit">
   
</form>
</body>
</html>
 
Ultima modifica di un moderatore: 5 Ott 2018
macus_adi

macus_adi

Utente Attivo
5 Dic 2017
1.343
91
48
IT/SW
  • 5 Ott 2018
  • #2
Crea un middleware per valorizzare l'input (post/get), fai che la var restituisca porzione di query...
 
Max 1

Max 1

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
29 Feb 2012
4.445
338
83
  • 5 Ott 2018
  • #3
@ONE313
Quando posti del codice PHP devi usare il TAG invece del TAG
Grazie
 

Rikk73

Utente Attivo
7 Apr 2015
141
6
18
Arezzo
  • 5 Ott 2018
  • #4
ONE313 ha scritto:
$Query = "SELECT nome,cognome,citta FROM utente,citta where utente.ks_citta=citta.id_citta
Clicca per allargare...

Credo che la query così ti restituisca i soli dati delle colonne "nome,cognome,citta" della tabella utenti e nulla della tabella città,
prova a modificare la query così:

PHP:
//...
$Query = "SELECT utente.nome,utente.cognome,utente.citta, citta.* FROM utente,citta where utente.ks_citta=citta.id_citta
//...
 
O

ONE313

Utente Attivo
10 Set 2016
37
2
8
  • 5 Ott 2018
  • #5
Max1 Ok.
Marcus_adi non so come si creano i middelware e come valorizzare l'imput get/post. Dove posso trovare riferimenti?
 
O

ONE313

Utente Attivo
10 Set 2016
37
2
8
  • 5 Ott 2018
  • #6
Rikk73, i dati me li estrae in entrambe le tabelle bene.
tabella utenti i campi sono:
id_nome(int autoincrement), nome(varchar),cognome(varchar), citta(int..... questo campo è relazionato con id_citta).
tabella citta
id_citta(int autoincrement), citta(carchar)
Ho relazionato le tabelle tra loro e la select ok, se io pero voglio filtrare i dati attraverso un select box o input non riesco.
ho pensato di usare like nella query ma da errore
$Query = "SELECT nome,cognome,citta FROM utente,citta where utente.ks_citta=citta.id_citta like ".$Citta." " ;
 

macus_adi

Utente Attivo
5 Dic 2017
1.343
91
48
IT/SW
  • 6 Ott 2018
  • #7
ONE313 ha scritto:
$Query = "SELECT nome,cognome,citta FROM utente,citta where utente.ks_citta=citta.id_citta like ".$Citta." " ;
Clicca per allargare...
Farei cosi:
PHP:
/**
* Metodo funzionale per effettuare il bind dei parametri
* @param array $bind Array associativo di valori
* @param string $type Stringa contentente i tipi
* @param bool $res Risultato fetchall
*
* @return $this|string
* @throws Exception
*/
private function execute_stmt($query,$bind,$type,$res=true){
   $this->stmt=$this->mysql->prepare($query);
   if($this->stmt->param_count != count($bind)){
      $this->exception='Numero di parametri non corretto per la query selezionata';
      return $this->exception;
   }
   $callArgs = array();
   foreach($bind as $index => $arg) {
      $callArgs[$index] = &$bind[$index];
   }
   try {
      array_unshift($callArgs, $type);
      call_user_func_array(array($this->stmt, 'bind_param'), $callArgs);
      $this->stmt->execute();

      if($res)$this->result=$this->stmt->get_result()->fetch_all(1);
      $this->stmt->close();
   }
   catch (Exception $e) {
      throw $e;
   }
   return $this;
}
$q = "SELECT nome,cognome,citta FROM utente,citta where utente.ks_citta=citta.id_citta like ?" ;
$tipologia='s';
$array_associativo=['citta'=>'Milano'];
$this->conn->execute_stmt($q,$array_associativo_valori,$tipologia)->result;
Questo è stato estratto solo ed esclusivamente da una mia Lib, in alternativa potresti utilizzare medoo.in
Notazione ad oggetti e non procedurale, quindi dovresti cambiare un pò di roba anche perchè i metodi che hai utilizzato sono deprecati già da un pò!
 
O

ONE313

Utente Attivo
10 Set 2016
37
2
8
  • 6 Ott 2018
  • #8
Ok, grazie della dritta. Mi guardo il metodo ad oggetti per capirlo e poi riprovo
 
Devi accedere o registrarti per poter rispondere.

Discussioni simili

U
PHP creare un file excel dopo ricerca nel DB
  • Umberto Federico
  • 15 Giu 2022
  • PHP
Risposte
0
Visite
1K
PHP 15 Giu 2022
Umberto Federico
U
G
Colorare menu select attraverso ricerca php
  • Gabriele_04
  • 18 Ott 2021
  • PHP
Risposte
0
Visite
1K
PHP 18 Ott 2021
Gabriele_04
G
L
  • Bloccata
PHP motore di ricerca nel sito
  • lugalzaggesi
  • 8 Ott 2021
  • PHP
Risposte
1
Visite
958
PHP 8 Ott 2021
Max 1
L
Ricerca sviluppatori PHP tempo indeterminato Milano
  • Lambdaict
  • 6 Lug 2019
  • Offerte e Richieste di Lavoro e/o Collaborazione
Risposte
0
Visite
1K
Offerte e Richieste di Lavoro e/o Collaborazione 6 Lug 2019
Lambdaict
L
S
[PHP] Creare collegamento filtri di ricerca al database
  • sal88
  • 25 Giu 2019
  • PHP
Risposte
6
Visite
3K
PHP 27 Giu 2019
sal88
S
L
[PHP] Ricerca su search bar esterna
  • Lorenzo Pezzi
  • 3 Mag 2019
  • PHP
Risposte
1
Visite
1K
PHP 3 Mag 2019
macus_adi
[PHP] Ricerca con risultati cliccabili
  • Alex_70
  • 14 Nov 2018
  • PHP
  • 2
Risposte
21
Visite
17K
PHP 17 Nov 2018
Alex_70
[PHP] motore di ricerca nel sito
  • ANDREA20
  • 5 Ott 2018
  • PHP
Risposte
11
Visite
2K
PHP 7 Ott 2018
macus_adi
T
[PHP] Ricerca nel database
  • titano
  • 29 Ago 2018
  • PHP
Risposte
2
Visite
5K
PHP 29 Ago 2018
titano
T
C
[PHP] Ricerca multipla, evitare if
  • cosworthwolf
  • 21 Giu 2018
  • PHP
Risposte
4
Visite
1K
PHP 21 Giu 2018
macus_adi
M
[OFFRO][RETRIBUITO] Milano IT Consulting SRL - Ricerca 1 Consulente PHP
  • milanoitcons
  • 2 Mag 2018
  • Offerte e Richieste di Lavoro e/o Collaborazione
Risposte
0
Visite
1K
Offerte e Richieste di Lavoro e/o Collaborazione 2 Mag 2018
milanoitcons
M
Da .htm a .php, perdo le mie posizioni su Google ricerca?
  • andreas88
  • 24 Gen 2018
  • SEO e Posizionamento
Risposte
9
Visite
2K
SEO e Posizionamento 23 Ott 2018
Salvatore HeadWolf
S
[PHP] Ricerca e modifica su due tabelle
  • Emix
  • 11 Dic 2017
  • PHP
  • 2
Risposte
26
Visite
4K
PHP 13 Dic 2017
Emix
G
[PHP] FORM DI RICERCA ESTESA
  • giacomo9783
  • 22 Ott 2017
  • PHP
Risposte
2
Visite
2K
PHP 28 Ott 2017
giacomo9783
G
[PHP] ricerca caratteri accentati
  • borgo italia
  • 25 Set 2017
  • PHP
Risposte
4
Visite
2K
PHP 25 Set 2017
borgo italia
P
[PHP] ricerca dati
  • paperinik4
  • 1 Ago 2017
  • PHP
Risposte
1
Visite
2K
PHP 2 Ago 2017
bubino8
[PHP][MYSQL] Ricerca avanzata tramite form
  • Emix
  • 1 Ago 2017
  • PHP
Risposte
6
Visite
3K
PHP 1 Ago 2017
Emix
[PHP] Problema ricerca con apostrofo
  • T4MAR4
  • 17 Lug 2017
  • PHP
Risposte
2
Visite
2K
PHP 18 Lug 2017
T4MAR4
R
[PHP] Prendere dati da moduli di ricerca esterni
  • Robertino841
  • 14 Lug 2017
  • PHP
Risposte
4
Visite
2K
PHP 15 Lug 2017
eraclio666
[PHP] piu select in ricerca
  • T4MAR4
  • 6 Lug 2017
  • PHP
Risposte
1
Visite
2K
PHP 6 Lug 2017
bubino8
Condividi:
Facebook X (Twitter) LinkedIn WhatsApp e-mail Condividi Link
  • Home
  • Forum
  • Fare Web
  • PHP
  • Italiano
  • Termini e condizioni d'uso del sito
  • Policy Privacy
  • Aiuto
  • Home
Community platform by XenForo® © 2010-2024 XenForo Ltd. | Traduzione a cura di XenForo Italia
Menu
Accedi

Registrati

  • Home
  • Forum
    • Nuovi Messaggi
    • Cerca...
  • Novità
    • Featured content
    • Nuovi Messaggi
    • Ultime Attività
X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?

X

Privacy & Transparency

We use cookies and similar technologies for the following purposes:

  • Personalized ads and content
  • Content measurement and audience insights

Do you accept cookies and these technologies?