Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Server Operation

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 22nd October 2011, 00:40
rutame rutame is offline
Senior Member
 
Join Date: Jun 2008
Location: Canary Islands, Spain, Europe, Planet Earth
Posts: 159
Thanks: 39
Thanked 0 Times in 0 Posts
Default How i can make a select from 2 or more tables

Hello to everyone

I need make a select from many tables, like this:

PHP Code:
SELECT FROM clientes,coches,vendedores WHERE clientes.nif="$nif" or coches.matricula ="$matricula" or vendedores.nif="$nif" 
But i need that the BD show only the register founded, and right now it show all registers.

I need this for one input text for search registers in the BD.

Thank you
Reply With Quote
Sponsored Links
  #2  
Old 22nd October 2011, 11:42
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,711
Thanks: 1,900
Thanked 2,702 Times in 2,545 Posts
Default

Quote:
Originally Posted by rutame View Post
But i need that the BD show only the register founded, and right now it show all registers.
What do you mean with that?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 22nd October 2011, 16:16
rutame rutame is offline
Senior Member
 
Join Date: Jun 2008
Location: Canary Islands, Spain, Europe, Planet Earth
Posts: 159
Thanks: 39
Thanked 0 Times in 0 Posts
Default

I mean that if the select found one register, for example: cliente.nif shows only that register, because now its load in the array registers from the 3 tables:

PHP Code:
$buscar = $_GET['buscar'];

$resultado = mysql_query ("SELECT * FROM vehiculos,clientes,vendedores WHERE vehiculos.matricula = '$buscar' or clientes.nif='$buscar' or vendedores.nif='$buscar' limit 1");

$ext=substr($foto1, -4);
$observaciones=nl2br($observaciones); //Esto es para respetar los saltos de linea.

while ($registro = mysql_fetch_row($resultado)) {  
    $foto1 = "$ruta_img"."$registro[2]";
  
    
    if (!empty($foto1)){
    $foto1 = "<img src=$foto1 class='fotito'>";
  }
      

    
    

?>
<a href=panel.php?modulo=vehiculo_uno&idv=<?php echo $registro[0];?>>
    <div id="registro_linea">

    
    <ul>
    
            <li>Fecha de alta: <?php echo $registro[1];?></li>
            <li>Nmero Chasis:<?php echo $registro[3];?></li>
            <li>Marca: <?php echo $registro[4];?></li>
            <li>Modelo: <?php echo $registro[5];?></li>
            <li>Matricula: <?php echo "$registro[6] | ""Fecha Matricula: $registro[7]";?></li>
            <li>Kilmetros: <?php echo $registro[8];?></li>
            <li>Precio de compra:<?php echo $registro[9];?></li>
            <li>Precio de venta: <?php echo $registro[10];?></li>
            <li>Situacin: <?php echo $registro[13];?></li>
        </ul>
      <?php echo $foto1;?>    
    </div>
   </a>

        
         <ul> <h2>DATOS DEL CLIENTE</h2>
                <li>Fecha de Operacin: <?php echo $registro[10];?></li>
                <li>NIF/CIF:<?php echo $registro[1];?></li>
                <li>Nombre:<?php echo "$registro[2]"."$registro[3]";?></li>
                
            </ul>
In this case $register[2] could to be cliente.nif and could be coches.matricula but if match cliente.nif if exist the script return vehiculo.matricula too, its weird, i dont know if i am explainig well...

Last edited by rutame; 22nd October 2011 at 16:19.
Reply With Quote
  #4  
Old 23rd October 2011, 18:01
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lneburg, Germany
Posts: 41,711
Thanks: 1,900
Thanked 2,702 Times in 2,545 Posts
Default

Try
Code:
SELECT coches.matricula ...
instead of
Code:
SELECT * ...
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 24th October 2011, 03:53
rutame rutame is offline
Senior Member
 
Join Date: Jun 2008
Location: Canary Islands, Spain, Europe, Planet Earth
Posts: 159
Thanks: 39
Thanked 0 Times in 0 Posts
 
Default

thank you Falko, i know that is very hard to explain my trouble with that code for two reasons: one i dont know speak well english and two always is dificult to explain things like that....

My task is make a search form in many tables and that only return the askeds values. Example i make:
select * from customers, cars, providers where customers.id="$search" or cars.num_plate="$search" or providers.id = "$search"

HTML Code:
<label for="Search">Search for Number Plate, Identification Personal, or Customer Code</label>
<input type="text" name="search" placeholder="N. Plate - Ident." />
Returns something like (for customer match):
Id: 123456789ABC
Name: Pepito Perez
.........
........

And the search returns something like this for coches (cars) match:
N. Plate: 0000ZZZ
Marca: BMW
Modelo: 325ci e92

Right now the query returns something like this:

N. Plate: 0000ZZZ
Marca: BMW
Modelo: 325ci e92
Id: 123456789ABC
Name: Pepito Perez

Good anyway i will try your tip, thanks althoug if you can i would like so much to know how i can to do that.

Thank you very much Falko (der komisar
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix not forwarding for some domains flappy Installation/Configuration 3 21st November 2010 17:57
CPU load locks up box. Apache or MYSQL related. crypted General 61 29th October 2010 22:16
Step by step email setup for domain & clients aurasdoom Installation/Configuration 17 19th January 2010 12:25
postfix: "unknown user" with mysql auth. Kruser Server Operation 3 18th June 2009 18:20
Rejected e-mail (unknown user) w/Postfix doronkeller HOWTO-Related Questions 9 27th January 2008 20:09


All times are GMT +2. The time now is 18:25.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.