results from the first query, use it to find and print other result in other ta

Good evening

I’m busy making a script but i’m am stuck…

How can i…

If i have te results from the first query, use it to find and print other result in other table…


query results from table A and retreve

  • Contains Name, telefone, info,
    Use the name of table A and find in Table B and retreve
  • Name, Adres, zipcode,

while $row mysql_fetch_array($result)
Echo all in 1 array

  • Name (Table A)
  • Telephone (Table A)
  • Info (Table A)
  • Adres (Table B)
  • Zipcode (TableB)

Hope some can help me(im a little noob)

You need to use sql join query:
[php]$r = mysql_query(“select A.*, Adres, Zipcode from A left join B on A.Name = B.Name order by A.Name”);
while($f = mysql_fetch_array($r)){
echo $f[‘Name’];
echo $f[‘Telephone’];
echo $f[‘Adres’];
}
[/php]

ok this was a good start for me thankx already for this…

just 1 error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pockta/domains/pockta.com/public_html/test2.php on line 23

<?php
include "db_config.php"; //verbinding maken
$query = mysql_query("SELECT producten_producten.leverancier,
                         t1.product, t1.categorie, t1.leverancier, t1.beschrijving, t1.opmerking, t1.verpakking, t1.eenheid, t1.product_url, t1.order_url, t1.name, t1.path
                         producten_leverancier.leverancier,
                         t2.lleverancier, t2.ladres, t2.ltelefoon, t2.lwebsite, t2.lemail, t2.lname, t2.lpath
                    FROM t1
               left join t2 on t1.id = t2.id where NOT ISNULL( t2.id )");
$result = mysql_query($query);
while($f = mysql_fetch_array($result))
{
        $f['product'] ;
		$product = $f['product'];
		$categorie = $f['categorie'];
		$beschrijving = $f['beschrijving'];
		$opmerking = $f['opmerking'];
		$verpakking = $f['verpakking'];
		$eenheid = $f['eenheid'];
		$product_url = $f['product_url'];
		$order_url = $f['order_url'];
		$name = $f['name'];
		$path = $f['path'];
		$lleverancier = $f['lleverancier'];
		$ladres = $f['ladres'];
		$ltelefoon = $f['ltelefoon'];
		$lwebsite = $f['lwebsite'];
		$lemail = $f['lemail'];
		$lname = $f['lname'];
		$lpath = $f['lpath'];
	        echo "product :$product<br>
				  categorie :$categorie<br>
				  beschrijving :$beschrijving<br>
				  opmerking :$opmerking<br>
				  verpakking :$verpakking<br>
				  eenheid :$eenheid<br>
				  product_url :$product_url<br>
				  product_url :$product_url<br>
				  order_url :$order_url<br>
				  name :$name<br>
				  path :$path<br>
				  lleverancier :$product<br>
				  ladres :$ladres<br>
				  ltelefoon :$ltelefoon<br>
				  lwebsite :$lwebsite<br>
				  lname :$lname<br>
				  lpath :$lpath<br>

				
";
}
include 'db_close.php';

?>

Try to echo mysql_error() after the query, this will show you where you mistake.

In this query, you refer to fields in 3 tables, not just 2. This table needs to be defined after “FROM” too: producten_producten. Also you’re missing comma after this field t1.path

owke now i have an other error…

Thankx already

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Resource id #4’ at line 1

[php]<?php
ini_set(‘display_errors’, ‘On’);
error_reporting(E_ALL | E_STRICT);
include “db_config.php”; //verbinding maken
$query = mysql_query("SELECT producten_producten.leverancier,
producten_producten.product,
producten_producten.categorie,
producten_producten.beschrijving,
producten_producten.opmerking,
producten_producten.verpakking,
producten_producten.eenheid,
producten_producten.product_url,
producten_producten.order_url,
producten_producten.name,
producten_producten.path,

                     producten_leverancier.lleverancier,
					 producten_leverancier.ladres,
					 producten_leverancier.ltelefoon,
					 producten_leverancier.lwebsite,
					 producten_leverancier.lemail,
					 producten_leverancier.lname,
					 producten_leverancier.lpath
                FROM producten_producten
           left join producten_leverancier on producten_producten.leverancier = producten_leverancier.lleverancier where NOT ISNULL( producten_leverancier.lleverancier )");

$result = mysql_query($query);
if(!$result) echo mysql_error(); else

while($f = mysql_fetch_array($result))
{
$f[‘product’] ;
$product = $f[‘product’];
$categorie = $f[‘categorie’];
$beschrijving = $f[‘beschrijving’];
$opmerking = $f[‘opmerking’];
$verpakking = $f[‘verpakking’];
$eenheid = $f[‘eenheid’];
$product_url = $f[‘product_url’];
$order_url = $f[‘order_url’];
$name = $f[‘name’];
$path = $f[‘path’];
$lleverancier = $f[‘lleverancier’];
$ladres = $f[‘ladres’];
$ltelefoon = $f[‘ltelefoon’];
$lwebsite = $f[‘lwebsite’];
$lemail = $f[‘lemail’];
$lname = $f[‘lname’];
$lpath = $f[‘lpath’];
echo "product :$product

categorie :$categorie

beschrijving :$beschrijving

opmerking :$opmerking

verpakking :$verpakking

eenheid :$eenheid

product_url :$product_url

product_url :$product_url

order_url :$order_url

name :$name

path :$path

lleverancier :$product

ladres :$ladres

ltelefoon :$ltelefoon

lwebsite :$lwebsite

lname :$lname

lpath :$lpath

";
}
include ‘db_close.php’;

?>[/php]

You need to change this line:
[php]$query = mysql_query("SELECT producten_producten.leverancier,[/php]

to this:
[php]$result = mysql_query("SELECT producten_producten.leverancier,[/php]

And completely remove this line:
[php]$result = mysql_query($query);[/php]

Thanx already,
ive got the result…

Only he only when the page request the data from the secon table…
he use only one record.

look to the result http://www.pockta.com/test2.php :-\

[php]

<?php ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); include "db_config.php"; //verbinding maken $result = mysql_query("SELECT producten_producten.leverancier, producten_producten.product, producten_producten.categorie, producten_producten.beschrijving, producten_producten.opmerking, producten_producten.verpakking, producten_producten.eenheid, producten_producten.product_url, producten_producten.order_url, producten_producten.name, producten_producten.path, producten_leverancier.lleverancier, producten_leverancier.ladres, producten_leverancier.ltelefoon, producten_leverancier.lwebsite, producten_leverancier.lemail, producten_leverancier.lname, producten_leverancier.lpath FROM producten_producten left join producten_leverancier on producten_producten.leverancier = producten_leverancier.lleverancier where NOT ISNULL( producten_leverancier.lleverancier )"); if(!$result) echo mysql_error(); else while($f = mysql_fetch_array($result)) { $f['product'] ; $product = $f['product']; $categorie = $f['categorie']; $beschrijving = $f['beschrijving']; $opmerking = $f['opmerking']; $verpakking = $f['verpakking']; $eenheid = $f['eenheid']; $product_url = $f['product_url']; $order_url = $f['order_url']; $name = $f['name']; $path = $f['path']; $leverancier = $f['leverancier']; $ladres = $f['ladres']; $ltelefoon = $f['ltelefoon']; $lwebsite = $f['lwebsite']; $lemail = $f['lemail']; $lname = $f['lname']; $lpath = $f['lpath']; echo "product :$product
categorie :$categorie
beschrijving :$beschrijving
opmerking :$opmerking
verpakking :$verpakking
eenheid :$eenheid
product_url :$product_url
order_url :$order_url
name :$name
path :$path
leverancier :$leverancier
ladres :$ladres
ltelefoon :$ltelefoon
lwebsite :$lwebsite
lname :$lname
lpath :$lpath

______________________
"; } include 'db_close.php'; ?>

[/php]

I believe, this is what you have in your database? Query is looking fine now.

Lol sorry, just wrong add in de database sorry

SOLVED thanks everyboddy

Sponsor our Newsletter | Privacy Policy | Terms of Service