0
   <?php
    $con=mysql_connect("localhost","root","");
     if (!$con)
      {
      die('Could not connect: ' . mysql_error());
   }
mysql_select_db("dbjobsheets", $con);
     $result = mysql_query ("select * from checklist union select * from checklistdailylogs;");

   while($row = mysql_fetch_array($result));

i tried everything in google but no luck. i tried also the join command and i got an error of mysql_fetch_array() expects parameter 1 to be resource.

still error in fetch array.

  $result = mysql_query ("select frequency from checklist union select daily from checklistdailylogs;");

i got no error on this but when i try to add another column like this

$result = mysql_query ("select frequency, sla from checklist union select daily, actualstart from checklistdailylogs;"); 

got mysql_fetch_array() expects parameter 1 to be resource.

1 Answers1

1

Your brackets are outside the SQL string, also your second table has no fields specified and the missing from for the other table selection; I assume you mean:

$result = mysql_query("(select * from checklist) UNION (select * from checklistdailylogs)"); 
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
harvey
  • 2,945
  • 9
  • 10
  • My bad, just remove the brackets completely. – harvey Oct 17 '14 at 03:02
  • 2
    `select * FROOOOOOMMMMMMM` –  Oct 17 '14 at 03:09
  • I am having a bad day :) For reference the correct SQL would be (assuming both tables have matching columns); "select * from checklist union select * from checklistdailylogs;" – harvey Oct 17 '14 at 03:12
  • @Dagon I wanted to change it to `FROOOOOOMMMMMMM` but I would have gotten a slap cross the head by the SQL gods. ;) – Funk Forty Niner Oct 17 '14 at 03:14
  • 3
    im calling all my table names to "from" to confuse others who come after me. select `from` from `from` where `from`="from" –  Oct 17 '14 at 03:15
  • i added from and copy paste the codes above i still got an mysql_fetch_array() error – dennis noriega Oct 17 '14 at 03:27
  • Instead of * specify the column names, make sure types, and number of columns match. If you still need more help run "show create table checklist;" and 'show create table checklistdailylogs;" and post the results for further help. – harvey Oct 17 '14 at 03:33
  • @Dagon Why stop there, randomly name `tables select, where, update, delete` and if you want to live dangerously `drop`. – harvey Oct 17 '14 at 03:36
  • $result = mysql_query ("select frequency from checklist union select daily from checklistdailylogs;"); <---- i got no error but when i try to add another column i have an error $result = mysql_query ("select frequency, rts from checklist union select daily, actualstart from checklistdailylogs;"); – dennis noriega Oct 17 '14 at 03:54