Sorry I am misunderstanding. You want me to change the dbtest.php or the profiletest.php? The dbtest is the one that we just created this morning. The profiletest is the original php file I am trying to get to work.
Please clarify.
Sorry I am misunderstanding. You want me to change the dbtest.php or the profiletest.php? The dbtest is the one that we just created this morning. The profiletest is the original php file I am trying to get to work.
Please clarify.
I updated the $sql line in the new dbtest.php file we created today and here is what I got. Apparently there is an error. What does this mean? Here is the link: http://www.fbgratings.com/members/dbtest.php
[php]1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
Testing DB Connection
Notice: Undefined variable: PlayerID in C:\inetpub\websites\FBGRatings.com\members\dbtest.php on line 57
QUERY: select * from FBGRatings WHERE PlayerID=
Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ‘=’., SQL state 37000 in SQLExecDirect in C:\inetpub\websites\FBGRatings.com\members\dbtest.php on line 59 SELECT from database failed!
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near ‘=’.[/php]
Well, in your live page, where you do the query SELECT, it has at the end ".$PlayerId; with a lower case d…
That might be your problem. Not sure if it is my copy or if it is like that in the live code…
The display of the query was for testing the live page. I think we are done with the test page. It was just
to make sure that the server and database was working correctly. Back to the live page to see what it is
doing wrong. Check where it queries the playerid… Check for spelling…
Wow…I think it worked! Just made sure that PlayerID was spelled correctly. Unreal. Thank you so much for the help!
So now, all of the numbers still contain one decimal place. Like instead of ‘32’ I am getting ‘32.0’. How do I correct that?
And another question: Now that I got the profiletest.php to work, how do I change the regular profile.php (which harbors our regular data for all of the players) to be correct? Is it a simple copy/paste in the new code?
The webpage uses the following format for all of the player links for example.
http://www.fbgratings.com/members/profile.php?pyid=1
The new one (based on profiletest.php, which I want to use the code to now get the new data table data) is:
http://www.fbgratings.com/members/profile.php?PlayerID=1
Note that the difference is that the old data table used pyid to determine the player ID but the new one that we have been working on now uses the column called PlayerID. How do I change all of the links to now properly show the new PlayerID column and get my site to reference all of the new data? Do I have to go into all the other .php files and change every instance where pyid is located to PlayerID?
Really happy for you! Finally getting it working. I saw that spelling error late last night but, could not find
it again when you asked about it. Sorry, could have had it fixed sooner… But, glad it is done!
Now, you had two new questions, but, keep them in this thread as they pertain to the same thing.
The formatting of numbers have been discussed here a lot in the past. For your project it is quite easy.
In your page, you waste a lot of time loading data into variables and I will discuss this at the end of this post.
But, for now, you have these types of lines that put the data and place them into variables:
$PlayerID = odbc_result($rs,"PlayerID"); $STR = odbc_result($rs,"STR"); $AGI = odbc_result($rs,"AGI"); $SPD = odbc_result($rs,"SPD");Now, think of this data in the database as a string. Basically even if it is a number it is stored in the form of a string. You just need to format the output so it has two decimals. This is the function you use for that: number_format($variable-to-fix,2) So, if AGI needs to be set to 2 decimals, try something like this: $AGI = number_format(odbc_result($rs,"AGI"), 2); format to 2 decimals from DB data There are a lot of other functions for displaying dollars as $1,234.56 or $...1,234.56 or many many other possible layouts to make displays align and look great. But, for now, let's just fix the 2 decimals...
The second question was the new profile page. Yes, if the new layout for the table uses PlayerID for it’s
main index, then you will have to change that. If all of the other fields are the same as the old code, then
most likely that is all you need to fix. You need to check the connection and the queries to see they are
fixed up in the same manner you did with the page we have been working on.
Now, to the programming errors… You have your code laid out loosely like this. (From your posted text file)
Connect to the database
Execute a query to locate the data needed for one player
Load all of the data from the query’s results into variables
Display the page including all of the variables just loaded
This looks straight forward and simple. But, let’s explain what is really happening. Step two is executing a
simple query pulling all of the selected player’s info into a variable array, in your case, named $rs. This data
is in a form not really set up for use. Next, you use a WHILE clause which uses odbc_fetch_row($rs) to do
the real fetch of one row of data from $rs. The output of this is actually placed into a variable data array.
It creates an array of data in the form of: odbc_result($rs, fieldname) Your code takes each of the fields
in that array and transfers it to a variable. Then, it displays the variable. This waste a ton of time as it is
not needed. Instead, just use the actual value to do the display. Here is the way one item is currently
handled in your code… (After the connection, query execution and odbc_fetch of the data)
In PHP area: $AGI = odbc_result($rs,“AGI”);
In HTML area:
Now, also, you should always end embedded PHP code and use the full PHP. This is not really for you, but,
In HTML area:
Also, at some point you will need to change all of your alignment to CSS as that is the standard, too. So,
the items like width=“10%” and align="" should not be in your HTML. It should just be done as CSS and
set to defaults for your entire website. CSS is very fancy these days and a lot can be done with it. I would
guess that would be another thread… LOL
OK - I am a novice…and I am now very, very, lost.
I want my results to have 0 decimal places. Right now they all have 1 decimal. How do I do that?
There are a lot of those .php files. Do I have to change the values for every single one of them? Like changing pyid to PlayerID, str to STR, etc…?
I have no idea what you are talking about with the whole PHP/HTML stuff. May as well be sanskrit to me.
I need to have it broken down as if I was a two year old. What do I change? How do I do it? How can I get this thing to work properly? Here is my current code. What do I do? I think you are throwing a bit too much at me at once. I have never done this website stuff before. I need smaller steps please.
profile.txt (20.8 KB)
Dcebb2001, yep, new that already. That is why I was explaining each thing as we move along…
Just remove the 2 from the function (default is no decimals). So, use this layout for that:
$AGI = number_format(odbc_result($rs,“AGI”)); Should return a number without decimals…
Well, since the “pyid” in the many many PHP files is only used in queries, I think you would find that it is
only used once or a few times in each page. Looking at the code, the pages were created by some
programmers with little experience and therefore you have a lot of pages that are most likely could be
combined into less pages, but…
The answer is NO if you have a utility to use to change them, like an programming editor which allows you
to do a mass-change. The answer is YES if you do not have that type of editor. But, again, it will go very
fast as there should only be one or two per page. What editor do you use to work on the site?
Not important at this point. If you want to learn programming and learn how to do things better, then,
it is a little important. But, saving 100 lines of code and making the page run 50% faster is a good thing!
I have to leave on a paying job soon. ( Karma does not buy groceries… LOL ) Will be gone for a couple
hours and will check in with you when I get back! Good luck!
OK I did the number format thingy for all of the variables that are numeric. The only issue I have now is that the field “DraftYear” looks like “2,015” instead of “2015”. Also, I have a weird zero before it. This weird zero is being replicated because in the database that is the name of the team that drafted the player.
So ideally, for PlayerID = 11, this player should have this for the draft year data:
Packers, 2014 - Round 5, pick 36 [176 overall]
But instead it looks like this:
0, 2,014 - Round 5, pick 36 [176 overall]
The 0 at the beginning is registering because the field called “DraftTeam” is not recognizing the text, so it is putting in the number 0.
How do I fix that too?
Thank you so much. I really appreciate the help. Here are my answers to your questions:
Did that and it worked aside from some year issues and the page not recognizing text and replacing it with 0s. See the post above.
I don’t have an editor. I am basically doing this through Microsoft Notepad. Recommendations?
I would love to clean all of this up and make it run faster. The people who coded this a long time ago did not do a good job. Alas, that falls onto me, and I have less experience than they did.
If you are curious as to how the profile pages are GOING to look when I do all of this, check out the attachment. As you can see, I am adding a ton more data than what is presently on the site. Hence the addition of this new data table that we successfully linked.
Thanks again for all the help! Oh, and you can call me Dan.
Welllllll, I didn’t think that you would just add formatting to everything. That was only for numbers.
So, a date field is NOT a number field. Unless you set it up that way in the database table. Normally,
dates are in a DATETIME format. But, some programmers use TEXT fields.
I mean, if you have a date field that is stored as TEXT, then it is NOT a date field but just text. Therefore, it
does not need formatting. You just add number formatting on your number fields. I think you get that!
Notepad! I really did the LOL thing! LAUGHED-OUT-LOUD! Actually, just did it again… Hee!
Well, since a good editor costs $$$ it might be easier for you to use Notepad++ . I have it on my system
to use for quick fixes. It has a lot of options. You can even open two files in it and compare them. Lots of
advanced things that you won’t use at this point. It is a free editor which looks like Notepad, but, has all
the bells and whistles. (Not a professional editor, but, will do 100% better than just notepad.) Get it at:
https://notepad-plus-plus.org/download
Well, Dan, there are many programmers on this site which will do the work for a fee. We have a section
about hiring a programmer. But, we are really here to help for free, so we can help you learn…
I did peek at the live page and it needs a lot of fine-tuning. I can help, just not for a couple hours…
Most of it looks like just adding in some CSS to style the alignments of the data to look better and make it
all easier to read. Minor things at this point…
I will check back in when I get back…
Cool deal. I downloaded Notepad++. Looks neat to me. At this point I really want to learn how to do all of this on my own so when I want to make changes, I can. Getting this site to look neat and hold all of the data is the goal. Getting it connected to the new data table was a big first step for me. Now, I just have to do what I can so I can navigate the site effectively, make it work, then make it look nice.
Thanks again! I will catch you later!
Yes, you are on the right track! And, this site will help you a lot as there are a lot of experienced programmers
here! One thing about Notepad++ When you are editing files, if you use the TAB key at the beginning of a
line you can use that to indent your code. This helps you and us to follow what is going on when you show a
section of code. And, why I mentioned this is that Notepad++ will draw a light line between the tags as you
write code. So, a
Okay, gotta head out… Later Dan… CYA in the Bitstream…
Thanks again.
I am slowly learning how to do this stuff in PHP. That C++ program is great! I am finding the intval() function to be working wonders.
Here’s another question: I have data values appearing like this: 2015-08-14 00:00:00.000.
How do I get rid of the hours/minutes/seconds/milliseconds, etc? Is there a good function for that?
The other thing I am working on is the layout of that page. I need to add some tables, flip some around, make some longer, make some shorter, etc. How do I do that?
Open separate topics for different issues.
Date->format lets you change how dates/times are displayed. First place to start looking.
So you want me to all of my questions in new topics? Is that right?
Going to be a lot of topics.
The forum can handle it - having them separate also makes it easier for future users to search find the questions (and answers). And it makes it easier to answer as you don’t get posts answering different questions jumbled together.
[php]$dateTimeString = ‘2015-08-14 00:00:00.000’;
$dateTime = new DateTime($dateTimeString);
echo $dateTime->format(‘Y-m-d’); // 2015-08-14[/php]http://php.net/manual/en/datetime.format.php
I’m not sure what to do with that code. Here is the line that the result containing the data coming out with those milliseconds, etc. is in. How do I modify this line by itself to make sure that the result only pulls in the day, month, year?
$RatingsLastUpdated = odbc_result($rs,“RatingsLastUpdated”);
Do a search… See if you can query access for the date portion specifically.