Jump to content

tpupaz

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

tpupaz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. So here's the code I wrote today and when I run this, it is able to pull the machine1 info and it spits it out nicely. I guess my question is - based off the queries, can I merge them into one maybe and then run a for loop that would increment machine and output the information there? My theory is that if I can merge all the data I query, I can then run a for loop , where $machine = 1 ; $machine <=10; $machine++; and that would run the loop 10 times and get the latest data for each machine so that its up to date. So the output would look like. Machine 1 HDD Total: 446345556 HDD Available: 4323455634 0 avg: 4353 5 avg: 5450 15 avg: 3425 Memory Available: 345324 Memory Total: 454235 Idle Time: .093 Machine 2 HDD Total: 43534243 etc etc etc Also I would have to add a rule in my loop that if $machine = 1 , then $machine = (text name - like Zeus) So it would show up as , Machine : Zeus instead of Machine : 1 Am I on the right path or can anyone provide constructive criticism in the way of helping me finish this out. Thanks much and its appreciated. I also realize that I'd have to redo the query so that it wold not serch just for machine = 1, but for all machines. I would just change the limit to 10 so I'd pull the top 10 by datetime , which would be the latest 10 to be updated (which the script would do). [code] include 'config.php'; $db = mysql_connect("$dbhost", "$dbuser", "$dbpass", $dbname); $dbname = mysql_select_db($dbname); $query  = "SELECT machine, available, total, dt FROM memory WHERE machine = 1 ORDER BY dt desc LIMIT 1"; $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) {     echo "Machine :{$row['machine']} <br>" .         "Available : {$row['available']} <br>" .         "Total :{$row['total']} <br>" . "Date/Time : {$row['dt']}<br><br>"; } $query_cpu = "SELECT machine, idle, dt FROM cpu WHERE machine = 1 ORDER by dt desc LIMIT 1"; $cpuresult = mysql_query($query_cpu); while($row = mysql_fetch_assoc($cpuresult)) {     echo "Machine :{$row['machine']} <br>" .         "Idle : {$row['idle']} <br>" .       //  "Total :{$row['total']} <br>" . "Date/Time : {$row['dt']}<br><br>"; } $query_load = "SELECT machine, 0avg, 5avg, 15avg, dt FROM `load` WHERE machine = 1 ORDER by dt desc LIMIT 1"; $loadresult = mysql_query($query_load); while($row = mysql_fetch_assoc($loadresult)) {     echo "Machine :{$row['machine']} <br>" .         "0 avg : {$row['0avg']} <br>" .         "5 avg :{$row['5avg']} <br>" .         "15 avg :{$row['15avg']} <br>" . "Date/Time : {$row['dt']}<br><br>"; } $query_hdd = "SELECT machine, available, total FROM hdd where machine = 1 ORDER by dt desc LIMIT 1"; $hddresult = mysql_query($query_hdd); while($row = mysql_fetch_assoc($hddresult)) {     echo "Machine :{$row['machine']} <br>" .         "HDD Available : {$row['available']} <br>" .         "HDD Total :{$row['total']} <br>"; } [/code]
  2. can you show me what you mean by having them keyed by machine.... we have 10 machiens, so i could write the 3 queries to pull the data from the 3 machines (tables) then i'd have all this info queried and then have to sort them to gert 10 outputs so for each machine i'd have the output... thanks in advance tony
  3. they will not have matching time stamps... all the tables have the same machine column, so they share that. Here's the query i'm working on right now but its not working $query = "SELECT cpu.idle, hdd.avilable, hdd.total, load.0avg, load.5avg, load.15avg, memory.machine, memory.available, memory.total, memory.dt" . "FROM cpu, hdd, load, memory WHERE memory.machine = hdd.machine AND memory.machine = load.machine AND memory.machine = cpu.machine ORDER BY memory.dt LIMIT 1"; $result = mysql_query($query);
  4. Ok so here's the problem, I'm building a query that will output data obv heh. Here's my layout and my idea. Each table has a common id that being "machine" field. So that much is good. Table Hard Drive id---------machine--------available---------total---------datetime Table Memory id---------machine--------available---------total----------datetime Table Load id---------machine---------5avg---------10avg---------datetime We have a script that updates these every 10 minutes , hence forth the datetime function in each table. What I had planned on doing was a multi table select and then output them for each one and have them go that way. We have 10 machines so what I would want the output to look like would be. Output Sample:: Machine: Fred HDD Avail: 50 GB HDD Total: 120 GB Memory Avail: 45 MB Memory Total: 120 MB 0AVG: .95 5AVG: 22 15AVG: 9.6 Machine: Joe etc etc etc I thought about having it do a for loop and to increment the machine number so it would cover all the machines, but my question is how do I get it to pull the latest one from the datetime function at the same time. My original idea was to have a select that ordered by datetime desc and then limited to one but that wont help with the output and would have to have me make 12 diff queries. I know theres an easier way but would like some input please. thanks T
  5. [!--quoteo(post=357726:date=Mar 23 2006, 01:55 PM:name=tpupaz)--][div class=\'quotetop\']QUOTE(tpupaz @ Mar 23 2006, 01:55 PM) [snapback]357726[/snapback][/div][div class=\'quotemain\'][!--quotec--] <?php //Connect To Database $hostname="hostnamehere"; $username="username"; $password="password"; $dbname="dbname"; $usertable="table_im_using"; $firstName = "field_iwant_to_query"; $lastName = "2ndfield_i_want_to_query"; /* mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); */ ?> [/quote] I've decided to comment out the mysql_connect section, so I could always select a new db if I have to. and add the variables to the list above. Does anyone have a good example of a global db.php file that I could look at to see if I'm doing this right? Thanks Tony
  6. Here is the dbconnect.php file that I've written for my website. My question is, I'm running one database with multiple tables, should I declare all the tables in this file so I can access them all from the different pages (in case i need to access diff tables)? I dont think I need to declare the fields though, I think that may be overkill from a tutorial I did previously. What about if I have multiple databases, do / can I declare both of those databases here also? What I'm trying to do is create one global file that I can include on all my php scripts as my db connector, then continue writing the code for my queries or other actions. Any advice would be great. Thanks much! Tony <?php //Connect To Database $hostname="hostnamehere"; $username="username"; $password="password"; $dbname="dbname"; $usertable="table_im_using"; $firstName = "field_iwant_to_query"; $lastName = "2ndfield_i_want_to_query"; mysql_connect($hostname,$username, $password) OR DIE ("Unable to connect to database! Please try again later."); mysql_select_db($dbname); ?>
×
×
  • 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.