0

My objective

Is to create a simple DB navigator for lambda users. For this, i have a side-bar which contains all DB table_name

And at the center of the page, i want the data. Here are my table names :

administratif
equipement
erreur
etablissement
interface_eth_routeur
interface_eth_switch
interface_ip_routeur
latence
mainteneur
routeur_arp
routeur_gsu
routeur_su
salle_visio
site
switch
switch_arp
switch_module

Now, there is the code : ROUTES.PHP

Route::get('navigateur_bdd', array('uses' => 'HomeController@navigateur_bdd', 'as' => 'navigateur_bdd'));
Route::get('navigateur_bdd/{table_name}', array('uses' => 'HomeController@bdd_show_table', 'as' => 'bdd_show_table'));

HOMECONTROLLER.PHP

public function navigateur_bdd()
{
    $table_name = DB::select('SHOW TABLES');
    return View::make('navigateur_bdd', array('which_actif' => 3, 'table_name' => $table_name));
}

public function bdd_show_table($argument = NULL) {
    $selected_table = DB::table($argument)->get();
    $table_name = DB::select('SHOW TABLES');
    return View::make('navigateur_bdd', array('which_actif' => 3, 'table_name' => $table_name, 'selected_table' => $selected_table));
}

The first function is the main view, when the user enters in this area.

The second function is used when the user clicks on the table_name from the sidebar of the main view

NAVIGATEUR_BDD.BLADE.PHP

 <div id="sidebar-wrapper">
    <ul class="sidebar-nav" id="sidebar">   
      <li class="well">Liste des tables</li>  
      @for ($i = 0 ; $i < count($table_name); $i ++)
          <li><a href="{{ URL::to('navigateur_bdd/' . $table_name[$i]->Tables_in_MYNET)}}">{{$table_name[$i]->Tables_in_MYNET}}</a></li>
      @endfor
    </ul>
  </div>

What is hapenning now ? Clicking on table names such as "administratif" or "erreur" is OK

But clicking on table names which are having a prefix like "routeur_" displays a blank page, with no error. I didn't set any prefix in the database.php because not all my tables have a prefix How can i figure this out ?

EDIT : Some tables with prefix are working. Not all, i don't know why...Like "switch" prefix :

"switch"
"switch_module"

are working, but not

"switch_arp"
routeur_su
routeur_gsu

are working but not

routeur_arp

After investigating, i have blank page on tables having a lot a rows (110 000 for example) (tried with dd($selected_table)); So this changes the title of my question : How can i store those 110 000 rows in a variable ?

Gui O
  • 363
  • 4
  • 8
  • 22
  • Can you first make sure by using `dd($argument)` at the beginning of your controller that the table name gets passed correctly to the controller? – lukasgeiter Nov 21 '14 at 13:14
  • It is correct. Each table name appears to be correct like this : string 'interface_ip_routeur' (length=20) – Gui O Nov 21 '14 at 13:37
  • And if you do the same thing but with `$selected_table`? – lukasgeiter Nov 21 '14 at 13:44
  • It don't display for the tables said before. I get it. The table for which it won't display the variable are the tables having 5000+rows (switch_arp have 110 000 rows) How can i do ? – Gui O Nov 21 '14 at 13:48
  • You think they have to many rows? What if you do this `DB::table($argument)->take(1000)->get()`? – lukasgeiter Nov 21 '14 at 13:50
  • It is working with 1000 rows – Gui O Nov 21 '14 at 13:52

1 Answers1

0

You can make use of Laravels pagination functionality.
It splits your data into pages and let's you generate links to get to each page...

$selected_table = DB::table($argument)->paginate(100); // how many records you wan't on one page

And then in your view do this to generate the links

{{ $table_name->links() }}
lukasgeiter
  • 147,337
  • 26
  • 332
  • 270