Jump to content

jason97673

Members
  • Posts

    62
  • Joined

  • Last visited

    Never

Everything posted by jason97673

  1. Yeah, I just did some research on my own and came up with this piece of code to do what I asked for $cmppct1 = number_format($cmppct, 1, '.', '');
  2. Hmm, at first I felt kind of stupid for not knowing to just multiply by 100 since its basic math but as others have posted since mine, seems like there is more too it. However, you said multiplication is only supported in version 6? Well My server has 5.2.6 and the code I entered was $cmppct = $row['cmppct'] * 100; This just retrieved a number from a database and multiplied it by 100 then it displayed perfectly in the form of xx.xx. So I dont know why its said that php versions less then 6 dont support it because it appears to have worked. But I have another simple question relating to this. Some of the data in the database might be a whole number like 68.0 but with the way I am doing the PHP most of the data has a decimal place while some do not. So I want to format the number to make sure it ALWAYS includes the decimal place such as 68.0 or 68.2 and so on instead of 68 and 68.2. Thanks
  3. Ok this should be a rather simple question. Im inserting data into a database with the number format being 0.6278(Sample number). Using PHP, how do I get this number to turn into 62.78? Should be simple, but unsure exactly how to do it as im a beginner.
  4. Well viewing the source of the page after the PHP is processed, it views like this: <table cellspacing="1" class="tablesorter"> <tr> <td><a href="<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> <p>Severity: Notice</p> <p>Message: Undefined variable: sort_column</p> <p>Filename: views/firstdown.php</p> <p>Line Number: 13</p> </div>firstdown/sort/name/asc/">Name</a></td> <td><a href="<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;"> <h4>A PHP Error was encountered</h4> Which is kind of messed up because there isnt even any DIVs on the page. I think that the DIV came from the server adding the PHP error messages.
  5. Ok cool, I got that syntax error under control. But now something crazy is happening. Doesnt appear to be detecting the <a href=" part of the code right before the PHP which appears to be messing up the page.
  6. Alright im lookin at the code, and pretty much copying it right now then Ill try and understand it. But after I copied the code into the view, appears to be a syntax error "unexpected ';'" right at the first line of the new code you gave me: <td><a href="<?php print (($sort_column == 'name' && $sort_order == 'asc') ? ('firstdown/sort/name/desc/') : ('firstdown/sort/name/asc/'); ?>">Name</a></td> I checked it out and do not see a syntax error.
  7. Thanks, itll probably take me a couple hours just to understand and digest everything you said. But ill give it a try and let you know if it works
  8. So I am new to useing codeigniter and there isnt as much documentation on this as there is just plain PHP without a framework. Well I am making a simple site (for now) that has many fields and is grabbing the records from a database. I want to be able to click on the column headers and sort them. I want to beable to have them be clicked and have it sorted DESC or ASC. Using regular PHP I can do this but not using the codeigniter framework. Ill show you the site. http://sykotic-designz.org When you visit the site it is a simple table with many fields and for now only 2 records. I want to beable to click name and have it sort from A-Z(then if possible have it sort the opposite direction if clicked again). Or if you click CMP, ATT, CMP % etc, have those sorted from higher to lower(then the opposite direction if possible when clicked again). My code right now in the view is <table border="1"> <tr> <td>Name</td><td>CMP</td><td>ATT</td><td>PCT</td><td>YDS</td><td>YPA</td><td>TDs</td><td>TD%</td><td>INTs</td><td>INT%</td><td>RAT</td> </tr> <? foreach($query->result() as $row): ?> <tr> <td><?=$row->lastname?>, <?=$row->firstname?></td><td><?=$row->cmp?></td><td><?=$row->att?></td><td><?=$row->cmppct?>%</td> <td><?=$row->yds?></td><td><?=$row->ypa?></td><td><?=$row->td?></td><td><?=$row->tdpct?>%</td><td><?=$row->ints?></td><td><?=$row->intpct?>%</td><td><?=$row->rating?></td> </tr> <? endforeach; ?> The code in the controller is class FirstDown extends Controller { function FirstDown() { parent::Controller(); } function index() { $data['title'] = "First Down Statistics"; $this->db->orderby("lastname", "asc"); $data['query'] = $this->db->get('firstdown'); $this->load->view('firstdown', $data); } } Thanks for any help.
  9. Eh well actually I have something similar to this. This is my code while($row = mysql_fetch_array($data)) { echo '<tr><td><a href="/data/profile.php?profileID=' .$row['id'] .'">' .$row['first'] .' ' .$row['last'] .'</a></td>'; echo '<td>' .$row['cmp'] .'</td>'; echo '<td>' .$row['att'] .'</td>'; echo '<td>' .$row['cmppct'] .'%</td>'; echo '<td>' .$row['yards'] .'</td>'; echo '<td>' .$row['ypa'] .'</td>'; echo '<td>' .$row['td'] .'</td>'; echo '<td>' .$row['tdpct'] .'%</td>'; echo '<td>' .$row['interceptions'] .'</td>'; echo '<td>' .$row['intpct'] .'%</td>'; echo '<td>' .$row['rating'] .'</td></tr>'; } But I actually want each of the results returned to display the actual NUMBER such as 1, 2, 3, etc.
  10. Not sure of the exact terminology for this, but I have a set of data in the database. About ten or so records are returned. I want the first row to display 1. ---Data returned 2. ---Data returned etc I know this involves a loop just unsure how to do this. Thanks.
  11. Thanks. I think that helps an aweful lot. Ill see what I can do wth it.
  12. Well I think I finally did what I have intended to do. However, the way I did it is probably the easy way which is probably bad coding. For my ten different tables or however mny I have, I created a variable for each one such as $firstDown = mysql_query("SELECT * FROM 1stdown where profileID='$profileID'"); $secondDown = mysql_query("SELECT * FROM 2nddown where profileID='$profileID'"); Then: $row1 = mysql_fetch_array( $firstDown ); $row2 = mysql_fetch_array( $secondDown ); And then simply displayed it in table format using $row1['cmp'] and $row2['cmp']. This looks to be the easy way and Id prob keep it that way unless I can find a way to do it all without many different queries. But this looks to be bad coding so Ill still be looking for ways to upgrade this.
  13. Thanks for the reply. I actually thought about using "aliases" after I made the post. However it is possible, I may have to combine 15 different tables with 10 columns in each table, and if I did that, that would be a very long query, and probably not proper coding. I just made the example shorter so it would be easy to understand. Perhaps it might be better coding to make a seperate page for this one very long query and "include" it.
  14. Is it possible to combine tables using PHP and MySQL. Basically, their is table1 and table2 each with multiple fiellds. Each row in each table will have a different ID(unique - primary key, but the different tables will have the same set of IDs). Is it possible to extract data from these two tables using PHP and work with the data on one page. For example what would be the proper syntax for this - select * from table1 and table2 where ID = abc1 Then you have the PHP part where I need to put the query into an array so I can work with the data. However, keep in mind, some, if not all of the column names in the two tables will be unique. When I have one table I usually use $data = mysql_query("SELECT * FROM table1 where id='abc1'"); $info = mysql_fetch_array( $data ); Then precede to display the data by using echo $info['column_name'] But if the tables I combined have the same column name, it wont work properly. I guess the proper way to say it or do it would be to create multiple queries on the same page because if you combine two tables that have the same column names, something would go wrong as you can't have the same column names in a database. Hope I explained this clearly.
  15. Well if you take a look at any sports website, just by looking at it, I think someone should beable to give me an idea of how to build a database like sites such as espn, nfl, etc. I dont think you really need to know about the NFL to understand what Im attempting but that is just what the site is about. Simply if you look at http://sports.espn.go.com/nfl/players/splits?playerId=5536 it would tell me that every player in the nfl has an id. But then there is like 50 different types of statistics for each player(Different statistics being the column on the farthest to the left on that link - totals, home, away, etc). For each statistic there would be many different fields(This would be the column headers on the link I showed - cmp, att, etc). If I want about 25 different statistic types and each type has 10 fields to it, it would be a little over 250 fields in one table and that seems like bad database design. Perhaps, I can do what I am already doing which is having a different table for each type of statistic and those tables have their fields. Which leads to my problem of combining all the tables of data onto one page in PHP so you can make a player clickable and see all of his statistics if you do not want side by side rankings which is what I have right now. Hopefully that makes it more general.
  16. Does anyone else have any ideas to this?
  17. Well Im confused as to what you mean exactly. Basically, I will not be doing the stats myself. Pretty much I am just gathering the stats from different resources and compiling them all in one place. My main reason for doing this is how I like splits statistics and most sites only have year by year and totals through out the career. And no sites from what I have seen have side by side comparisons. Pretty much I will just be including stats such as the different quarters, down, behind, ahead tied, in a win or loss etc.
  18. I am working on creating a website that has alot of quarterback statistics from the NFL. Mainly splits such as 3rd downs, playing from behind etc. Right now I dont have a problem, but my idea of what to do is simply create a table for each split(such as 3rd downs, 1st quarter, etc). And in that table I have the Quarterbacks stats for the individual stat. But instead of making 100 tables for all the different type of split statistics, is there an easier way to do this. My idea is to create a website that will have all the QB's on one page for a particular stat. But I will eventually want to also make an individual QB clickable and show his stats. Sort of how ESPN has it(http://sports.espn.go.com/nfl/players/splits?playerId=5536). But if I create many different tables, I dont think it is possible to list that QBs splits all on one page using PHP. Having one table with 1000 fields doesnt appear to be good database design either. Basically how would a site like ESPN probably design there player statistics database or any of the other sports websites? Basically I am just looking for ideas as to what the best database design would be. Thanks for any ideas.
  19. Thanks, I will try implement this into my code
  20. So I am sure you know how when you click a header on a column of data it sorts from largest to smallest? Then you want to click the column header again and sort the opposite direction, smallest to largest. I am using MySQL obviously, and currenly I have my data sorted from largest numbers to smallest. However if you click the column header again, I want it to sort the opposite direction. Here is the code I have that sorts DESC $page_name="1st_downs.php"; // If you use this code with a different page ( or file ) name then change this @$column_name=$_GET['column_name']; // Read the column name from query string. $start=$_GET['start']; // To take care global variable if OFF if(!($start > 0)) { // This variable is set to zero for the first page $start = 0; } $eu = ($start - 0); $limit = 100; // No of records to be shown per page. $this1 = $eu + $limit; $back = $eu - $limit; $next = $eu + $limit; /////////////// WE have to find out the number of records in our table. We will use this to break the pages/////// $query2=" SELECT * FROM 1st "; $result2=mysql_query($query2); echo mysql_error(); $nume=mysql_num_rows($result2); /////// The variable nume above will store the total number of records in the table//// /////////// Now let us print the table headers //////////////// echo '<div id="main" class="text">'; echo '<table>'; echo "<tr>"; echo "<td><a href='$page_name?column_name=quarterback'>Quarterback</a></td>"; echo "<td><a href='$page_name?column_name=completions'>Completions</a></td>"; echo "<td><a href='$page_name?column_name=attempts'>Attempts</a></td>"; echo "<td><a href='$page_name?column_name=comp_percent'>Comp%</a></td>"; echo "<td><a href='$page_name?column_name=yards'>Yards</a></td>"; echo "<td><a href='$page_name?column_name=ypa'>YPA</a></td>"; echo "<td><a href='$page_name?column_name=touchdowns'>Touchdowns</a></td>"; echo "<td><a href='$page_name?column_name=td_percent'>TD%</a></td>"; echo "<td><a href='$page_name?column_name=interceptions'>Interceptions</a></td>"; echo "<td><a href='$page_name?column_name=int_percent'>INT%</a></td>"; echo "<td><a href='$page_name?column_name=rating'>rating</a></td>"; echo "</tr>"; ////////////// Now let us start executing the query with variables $eu and $limit set at the top of the page/////////// $query=" SELECT * FROM 1st"; if(isset($column_name) and strlen($column_name)>0){ $query = $query . " order by $column_name"; } $data=mysql_query($query); echo mysql_error(); //////////////// Now we will display the returned records in side the rows of the table///////// while($row = mysql_fetch_array($data)) { echo '<tr><td>' .$row['quarterback'] .'</td>'; echo '<td>' .$row['completions'] .'</td>'; echo '<td>' .$row['attempts'] .'</td>'; echo '<td>' .$row['comp_percent'] .'%</td>'; echo '<td>' .$row['yards'] .'</td>'; echo '<td>' .$row['ypa'] .'</td>'; echo '<td>' .$row['touchdowns'] .'</td>'; echo '<td>' .$row['td_percent'] .'%</td>'; echo '<td>' .$row['interceptions'] .'</td>'; echo '<td>' .$row['int_percent'] .'%</td>'; echo '<td>' .$row['rating'] .'</td></tr>'; } echo "</table>"; Thanks for any help..
  21. I got most of the script from a tutorial online and was messing with it, and I just deleted a line in the code and seemed to work. I think I had the line of code duplicated and it messed it up somehow.
  22. Ok actually those numbers I gave were probably a bad example. A better one would be something 1200, 500, 2200. It would show 1200, 2200, then 500. But I think I fixed it. It had something to do with the limit I believe.
  23. Im working on a project now and I ran into some sort of sorting problem. Seems like it might be common and seems like it should be easy to fix. I have my set of data which consist of mainly numbers however when clicking on the header links to sort the data it wants to sort everything using the first number. For example if you have 1200, 8, 340, it will show up in the order of 1200, 340, 8 cause it is only looking at the first numbers( 1xxx, 3xx, 8 ). Would this be something in the database or PHP? I have this at http://5star-technologies.com/1st_downs2.php?column_name=completions so you can see for yourself. In my queries, I simply have order by column name. I havent run into this problem so I wouldnt know what part of the code to show, but Im guessing its a common problem. Thanks for any help.
  24. Thanks, ill give that a try tomorrow and reply or mark it solved
×
×
  • 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.