Include this into my code..

Discussion in 'PHP' started by adamjblakey, Jul 17, 2008.

  1. #1
    Hi,

    I currently use this for extracting data from my DB.

    
    $new = new database;
    	$new->selects("SELECT * FROM table");
    	$result = $new->getRes();
    	$countrows = $new->countrows(); 
    	
    	$smarty->assign('result', $result);
    	$smarty->assign('countrows', $countrows);
    
    PHP:
    I have come across this though to extract data but includes pagnation also.

    
    $dataCollection = array();
    $getData = mysql_query("SELECT * FROM table");
    $countrows = mysql_num_rows($getData);
    
    while ($r=mysql_fetch_array($getData)) {
    $tmp = array(
                  'field1' => $r['field1'],
                  'field2'=> $r['field2'],
                  'field3'=> $r['field3'],
                  'field4'=> $r['field4'],
                  'field5'=> $r['field5']
                  );
    
                  array_push($dataCollection, $tmp);
    
    }
    
    // Assign the results to an array
    $pagination = new pagination();
    $dataPages = $pagination->generate($dataCollection, 6);
    $smarty->assign('listing', $dataPages);
    $smarty->assign('pagination', $pagination->links());
    $smarty->assign('countrows', $countrows);
    
    PHP:

    My question is there any way to include the pagnation section into the first example as i don't like having to list all my fields.

    Cheers,
    Adam
     
    adamjblakey, Jul 17, 2008 IP
  2. Hallent

    Hallent Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    replace this in the second part should do the trick
    $tmp = array();
    foreach ($r as $key=>$value) {
    $tmp[$key] = $value;
    }
     
    Hallent, Aug 2, 2008 IP