Welcome, Guest. Please login or register.
Did you miss your activation email?
02/03/12, 23:50
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  Server side Scripting and Database Support
| |-+  PHP, Perl, ASP, JSP, CFM (Moderators: Flash-db, Musicman, vesa kortelainen, Ronald Wernecke, Jorge Solis, nothingGrinder)
| | |-+  select from 2 tables -> array
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] Print
Author Topic: select from 2 tables -> array  (Read 2416 times)
till
Seasoned Programmer
***
Posts: 200



View Profile WWW Email
« on: 01/09/10, 07:36 »

hi.
someone please help me with this:

i have 2 tables:

table aktuell: (workshops)



and table termine: (dates) ( ws_id is the reference to id in table aktuell )



a workshop can have more than one target dates.
my problem now is to select both tables and put it ino an array.
also there is a pagination- function.

the result should be:

Title: xxxxxxxxxxxxxxxx
date #1: xx.xx.xxxx
date #2: xx.xx.xxxx
date #3: xx.xx.xxxx



Title: yyyyyyyyyyyyyyyy
date #1: xx.xx.xxxx

...and so on...

Code:

$dataCollection = array();
$getData ="SELECT * FROM $table_termine".$pre_fix." GROUP BY ws_id ORDER BY datum ASC";
$result = mysql_query ($getData) or die ("invalid query1 ".$getData);   
$num =  mysql_num_rows($result);


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


/* print('<pre>');
print_r($row);
print('</pre>');  */

$table_aktuell".$pre_fix.".id = $table_termine".$pre_fix.".ws_id GROUP BY $table_aktuell".$pre_fix.".titel ORDER BY $table_termine".$pre_fix.".datum ASC";

$querystring2 = "SELECT *  FROM $table_aktuell".$pre_fix."  WHERE deleted = 'false' AND id = '".$row['ws_id']."'";
$getData2 = mysql_query ($querystring2) or die ("invalid query2 ".$querystring2);   
$num2 =  mysql_num_rows($getData2);




if ($rowData = mysql_fetch_assoc($getData2)) {
do {
$dataCollection[] = $rowData;

/* print('<pre>');
print_r($dataCollection);
print('</pre>'); */


/* $getData3 ="SELECT * FROM $table_termine".$pre_fix." WHERE ws_id = '".$row['ws_id']."' ORDER BY datum ASC";
$result3 = mysql_query ($getData3) or die ("invalid query1 ".$getData3);   
$num3 =  mysql_num_rows($result3);

while($row3 = mysql_fetch_assoc($result3)) {


//echo $row3['datum'].'_'.$row['ws_id'].'<br>';

print('<pre>');
print_r($dataCollection);
print('</pre>');



array_push($dataCollection[], $row3);

} */



} while($rowData = mysql_fetch_assoc($getData2));


/* print('<pre>');
print_r($dataCollection);
print('</pre>'); */



}

}


include 'php-array-pagination/pagination.class.php';

$pagination = new pagination;





//************************_DISPLAY_FILTER_*****************************
 $count = 0;
   
     foreach ($dataCollection as $testArray) {

$value = $testArray['datum'];

if($display_out_of_date == "false"){ // $display_out_of_date = variable aus html_config

if($value < today()){

//echo "VALUE = ".$value."<br>";

if (false !== ($key = array_search($value,$dataCollection[$count])))
  {
                  unset($dataCollection[$count]);
              }
         }}

//********************************************

      $value = $testArray['display'];

if($value == "false"){

//echo "VALUE = ".$value."<br>";

if (false !== ($key = array_search($value,$dataCollection[$count])))
  {
                  unset($dataCollection[$count]);
              }
         }


$count++;

}

//******************************************************


//********************____CONTENT____************************************************************

if (count($dataCollection)) {

          $productPages = $pagination->generate($dataCollection, $ws_display_value);

         
          if (count($productPages) != 0) {
           
$pageNumbers = '<div align="center" class="numbers">'.$pagination->links().'</div>';


echo '<table width="614" valign="top" align="left">';

// Loop through all the items in the array
            foreach ($productPages as $productArray) {

               
              echo '<tr><td align="left">
  <span class="uberschrift">'.$productArray['titel'].'&nbsp;<br>'.if_date(0,$productArray['datum']).'&nbsp;'.if_date(1,$productArray['datum_bis']).'</p>
  <p align="justify">';
 
  //.if_image($productArray['img'],$productArray['display_img']).'
// echo $productArray['id'];


//******  DISPLAY IMAGE  *********************************************


$querystring2 = "SELECT *  FROM $table_images".$pre_fix." WHERE type = 'aktuell' AND parent_id = ".$productArray['id']." ";
$result2 = mysql_query ($querystring2) or die ("invalid query ".$querystring2);   



 while ($row2 = mysql_fetch_object($result2)){
 
 $image = $row2->image;
 
// echo $image;
 //if_image($row2->image,$productArray['display_img']);

if($productArray['display_img'] == "true"){

echo '<img src="upload/thumbs/'.$image.'" border="0" hspace="0" vspace="0" style="float: left; padding-right: 5px; padding-bottom: 1px;"/>';

}

 }


//******************************************************************


 
 
 
  echo '<span class="text">
  '.myTruncate($productArray['text'],$text_cut).'</span></p>
 
              <p align="right" class="text"><a href="aktuell_detail.php?nav='.$nav.'&page='.$page.'&ws_id='.$productArray['id'].'">mehr Info &amp; Anmeldung.... </a></p></td></tr>';
           
}
            // print out the page numbers beneath the results

//echo '</table>';

echo '<tr><td align="center">';

            echo $pageNumbers;

echo '<br></td></tr>';

echo '</table>';
echo '<br><br>';
          }
        }
//}

      $gets = '&page='.$page;




?>





thanks.
till.
Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6161


View Profile WWW Email
« Reply #1 on: 01/09/10, 08:27 »

how about this:

Code:
select datum, datum_bis, extra, zeit, zeit_bis, titel, display from termine, workshops where workshops.id=ws_id order by datum, zeit

Then you have the list - if you want to page, you need a LIMIT statement at the end.

LIMIT $begin, $length_of_page

where begin is the record, where to start - be aware, counting starts with 0.
Logged

happy flashing
Cool
Ronald
Pages: [1] Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!