Jump to content

Script Won't Get All Database Info


Go to solution Solved by mlk77,

Recommended Posts

I got a script that I'm going to run on my home server and the coder no longer has anything to do with this project and I can't seem to reach him. I installed everything but it's only grabbing the information from the first table. I've been messing around with it and can't seem to figure it out. Ay help would be great!

 

 

  unset ($tanks);

  require_once("./inc/general_functions.php");
  require_once("./inc/Calendar.php");
 
  getHeader(getcwd());
?>
    <h2 align="center" class="center">Fish Tank Database </h2>
    <?php
 
  print getBreadCrumb();

  $units = getUnits();
  $tanks = getTankObjects();

  foreach ($tanks AS $tank) {

    print "<table cellpadding=\"3\" cellspacing=\"0\" width=\"80%\" class=\"contentTable\" align=\"center\">\n";
    print "<tr><td><h3>" . $tank->tank_name . " (<a href=\"./livestock.php?tank_id=" . $tank->tank_id . "\">view livestock for this tank</a> |
           <a href=\"./expenses.php?tank_id=" . $tank->tank_id . "\">view expenses for this tank</a>)</h3></td></tr>\n";
    print "<tr><td>Tank Size: " . $tank->tank_size . " " . $units['size_unit'] .  " (" . convertSize($tank->tank_size, $units['size_unit']) . ") </td></tr>\n";
    print "<tr><td>" . $tank->tank_desc . "</td></tr>\n";
    print "</table><br />\n";

Link to comment
https://forums.phpfreaks.com/topic/285531-script-wont-get-all-database-info/
Share on other sites

The complete code for this file is below.  It will only show the first entry in the database. I'm trying it on ubuntu server 12.04

<?php

/*
    This file is part of TankLogger.

    TankLogger is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    TankLogger is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with TankLogger; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA


    Copyright 2002, 2003, 2004 Jason Nugent
    jnugent@ns.sympatico.ca
*/

  unset ($tanks);

  require_once("./inc/general_functions.php");
  require_once("./inc/Calendar.php");
 
  getHeader(getcwd());
?>
    <h2 class="center">Tanks that TankLogger is currently storing data for:</h2>
<?php
  
  print getBreadCrumb();

  $units = getUnits();
  $tanks = getTankObjects();

  foreach ($tanks AS $tank) {

    print "<table cellpadding=\"3\" cellspacing=\"0\" width=\"80%\" class=\"contentTable\" align=\"center\">\n";
    print "<tr><td><h3>" . $tank->tank_name . " (<a href=\"./livestock.php?tank_id=" . $tank->tank_id . "\">view livestock for this tank</a> | 
           <a href=\"./expenses.php?tank_id=" . $tank->tank_id . "\">view expenses for this tank</a>)</h3></td></tr>\n";
    print "<tr><td>Tank Size: " . $tank->tank_size . " " . $units['size_unit'] .  " (" . convertSize($tank->tank_size, $units['size_unit']) . ") </td></tr>\n";
    print "<tr><td>" . $tank->tank_desc . "</td></tr>\n";
    print "</table><br />\n";
  }

  displayVersion();
  getFooter(getcwd());
?>



The last code is the full php file that I'm having the problem with. I have it running on a local server that don't have access to the outside. The Script is called Tanklogger and is on Source Forge but the demo isn't working. It's for keeping informtion on my fish tanks. When it adds information to the data base it should be the tank name, decription of the tank,tank size and the date I set it up.

 

The table for the SQL is

CREATE TABLE tanks (tank_id int unsigned  auto_increment primary key, tank_name tinytext not null, 
                    setup_date datetime not null, tank_size mediumint unsigned not null, tank_desc text not null);

I can go in phpmyadmin and change the first tank id to 3 and the second tank information will show. Right now I have 3 tanks listed but the script is only grabbing the first one.

that script is pretty bad. functions wrapping classes using globals, running queries only to run more queries inside of loops getting the same data the first query could have...

 

start by debugging what data is in $tanks in the code you posted. what does the following show when added right before the foreach(){} loop -

echo '<pre>'; var_dump($tanks);

edit: see the following reply.

Edited by mac_gyver

actually, i just determined why the code doesn't work. the kid who wrote it didn't have a clue, nor did he test the code, and his database class is storing the result set within the database object, rather than returning an instance of a result object, combined with trying to loop over the result from one query to get more query results.

 

the offending code starts in the getTankObjects() function and the tank class and in the use of the database object. but given how bad just the code for this 'tanks' display is, do you really want to try and go through and fix everything else it is likely doing wrong?

Edited by mac_gyver
  • Solution

Thanks for the reply.. I gave up on that version and downloaded a older version.for some reason his older versions actually look like coding that I can understand. I don't know what was going on on the current version at all. I have the older version working much better. I did start to redo it and figures with all the files it wasn't worth it as you said. I just need to change a few things in that version for photos and should be set.

 

Thanks again!!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.