Mam zpytanie do dwóch tabel jednocześnie, przykład
$zapyt = mysql_query("select * from tabela1 t1, tabela2 t2 where t1.nazwa='".$_POST[nazwa]."' or t2.nazwa='".$_POST[nazwa]."' ");
Teraz jak wyciągnąć id tylko z "tabela1" ?
$zapyt = mysql_query("select * from tabela1 t1, tabela2 t2 where t1.nazwa='".$_POST[nazwa]."' or t2.nazwa='".$_POST[nazwa]."' ");
$zapyt = mysql_query("select t1.id from tabela1 t1, tabela2 t2 where t1.nazwa='".$_POST[nazwa]."' or t2.nazwa='".$_POST[nazwa]."' ");
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /... on line 60
$zapytanie = mysql_query("select * from articles t1, articles_categories t2 where t1.articles='".$_POST[articles]."' or t2.articles_categories='".$_POST[articles_categories]."' ");
$sql = "SELECT a.id, a.id_cat, a.tresc, a.opis, a.data, b.id, b.nazwa, b.opis FROM articles a LEFT JOIN articles_categories b ON a.id_cat = b.id";
$x=1; $zapytanie = "SELECT a.id, a.id_cat, a.tresc, a.tytul, a.data, b.id, b.nazwa FROM articles a LEFT JOIN articles_categories b ON a.id_cat = b.id"; { </table>'; $x++; }
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /... on line 60
A jeśli chcesz ograniczyć wyniki np. do konkretnej kategorii, to do zapytania dopisujesz odpowiednią klauzulę WHERE.
SELECT a.id id, a.tytul tytul, a.DATA DATA, ac.nazwa kategoria FROM articles a LEFT JOIN articles_categories ac ON ac.id=a.id_cat
A kolega chce wyciągnąć tylko konkretne kolumny. Poza tym nie będzie czegoś takiego jak $wynik['a.tytul'].
SELECT a.*, ac.* FROM articles a LEFT JOIN articles_categories ac ON ac.id=a.id_cat
$zapytanie=mysql_query("SELECT * FROM articles AS a INNER JOIN articles_categories AS ac WHERE a.id_cat=ac.id");