Webmaster Forum

Go Back   Webmaster Forum > Web Development > Coding Forum

Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more.


Closed Thread
 
Thread Tools Display Modes
Share |
  #1  
Old 02-06-2017, 09:48 AM
Gdec Gdec is offline
Junior Member
 
Join Date: 12-04-09
Posts: 24
iTrader: 0 / 0%
Database / Coding Question

I have to admit that I really don't know where to start on this so I am just looking for some direction on sites or articles that might help me.

I have a spreadsheet or database with a list of colors, numbers and other statistics. There will be thousands of entries in the database. I would like to make a web page for each color that would also list all of the information from the database. I'm not sure how I would automatically create all of these pages.

Any ideas?
 

Advertisement

Advertisement

  #2  
Old 02-06-2017, 12:37 PM
gxnpt's Avatar
gxnpt gxnpt is offline
Contributing Member
 
Join Date: 09-10-16
Location: far west Florida near Destin
Posts: 104
iTrader: 0 / 0%
Sounds like you are going to do a SELECT where 'color' = something and adjust the HTML or Javascript with the results.

With PHP would just insert variable values from the database into a templated page.
 
  #3  
Old 02-06-2017, 09:14 PM
Altssolution's Avatar
Altssolution Altssolution is offline
Contributing Member
 
Join Date: 01-29-17
Location: v7n.com
Posts: 195
iTrader: 0 / 0%
Use PHP to Fetch the data from MySQL
Based on the MySQL data, Write if else to get the color string (red, blue) in a $variable
Use that in HTML code

<body bgcolor="<?php echo $variable; ?> ">
 
  #4  
Old 02-07-2017, 05:21 AM
ScriptMan's Avatar
ScriptMan ScriptMan is online now
Super Moderator
 
Join Date: 02-10-07
Location: Central Kentucky
Posts: 14,023
iTrader: 4 / 100%
What format is the data currently in?

How organized is it?
 
  #5  
Old 02-18-2017, 02:05 PM
Rukbat's Avatar
Rukbat Rukbat is offline
Contributing Member
 
Join Date: 08-08-11
Location: Long Island, NY, USA
Posts: 294
iTrader: 0 / 0%
Quote:
Originally Posted by mindmyweb View Post
first thing you would do is then import that into a mysql database via phpmyadmin by converting the spreadsheet to .csv and then just generate a two page website on that loops though your table and picks up the hex of each color make sure you represent it with a clickable box. You can add the id of the individual entry in the URL that you will pass to the individual page
It would be just as easy to use a single page PHP program that uses AJAX to allow the user to make his choice, sends it back to the server, which sends the page changes back to the browser.

(And writing a PHP or even VB program to scan a spreadsheet file and write it to a database is just a trifle more difficult than trivial. Even PEAR has examples in PHP.)
 
  #6  
Old 02-18-2017, 05:04 PM
gxnpt's Avatar
gxnpt gxnpt is offline
Contributing Member
 
Join Date: 09-10-16
Location: far west Florida near Destin
Posts: 104
iTrader: 0 / 0%
What constitutes trivial is going to vary depending on who you ask. Unless the data uses some odd formatting I would call the PHP script fairly trivial to move from csv to database.

But it is easy enough to have a page submit to itself with a mix of Javascript and PHP - I believe AJAX is a standardized structure for such ( I just write such things on the fly and still call them PHP/Javascript interweaves. )

Once data is in the database:

Page accessed - with no supplied variables uses default settings
- when values are submitted it will make use of them instead

Server-side:
PHP script reads any submitted values and then reads the database for the matching info.
Page template has values substituted and is sent to browser.
Values not displayed can be stored as Javascript values or plugged into hidden form fields for options belonging to a single item.

Client-side:
When items are selected Javascript/CSS makes dynamic changes from options values and if a new item is selected makes the page submit info to itself.

Having a page submit to itself is also a trick to get around the IE white flash on page load/reload - no flash when is a submit instead of a reload.
 
  #7  
Old 02-19-2017, 11:35 AM
Rukbat's Avatar
Rukbat Rukbat is offline
Contributing Member
 
Join Date: 08-08-11
Location: Long Island, NY, USA
Posts: 294
iTrader: 0 / 0%
Quote:
Originally Posted by gxnpt View Post
I would call the PHP script fairly trivial to move from csv to database.
I'd call the PHP code to read the spreadsheet directly fairly trivial too - but then, I'd been doing that for about 5 years before I retired. It was like sweeping the floor - boring, but it had to be done.

Quote:
But it is easy enough to have a page submit to itself with a mix of Javascript and PHP - I believe AJAX is a standardized structure for such
Easy? Yes. Standard? Anything but. You don't mix M, V and C in a single file. Wait until you have a 50k file and you have to fix some little but - and you forgot to comment that section. Have Javascript call a dozen (or more) PHP files using AJAX and it's trivial. (You start planning for scaling from the start, not after you have to scrap the site and start over.)

Quote:
Once data is in the database:

Page accessed - with no supplied variables uses default settings
- when values are submitted it will make use of them instead
You just send the calues to the server - don't include any data about the structure of the database.

Quote:
Page template has values substituted and is sent to browser.
PHP page sends data back to the browser - the browser formats the data, fits it to a template (usually not necessary - if there's that much data, it's probably faster to send the browser a new page).[/quote]

Quote:
Values not displayed can be stored as Javascript values or plugged into hidden form fields for options belonging to a single item.
Or shouldn't have been sent (or requested) at all.

Quote:
Client-side:
When items are selected Javascript/CSS makes dynamic changes from options values and if a new item is selected makes the page submit info to itself.
NO!

The values are changed on the page itself, the page isn't submitted. Submission is the last thing a page does - it should close access to that page.

Quote:
Having a page submit to itself is also a trick to get around the IE white flash on page load/reload - no flash when is a submit instead of a reload.
Neither is there a flash when Javascript sends data to a PP page and gets data in the AJAX callback - which is the whole reason for AJAX. If you submit a page - AJAX, PHP, anything else - you end the page and move on to the next one.

Your method sounds like someone who just happened on an AJAX site, scanned a fw lines and knows how to send Javascript data to PHP - without understanding the whole reason for using AJAX. AJAX prevents all the problems you claim your "submit without submitting" trick does - a lot faster, with a lot less code and cleaner.
Study it for a few years, then see why it shouldn't be done your way. (Or go to Jackson, MS - there's a great programmer there who could explain AJAX to you in a week.)
 
  #8  
Old 02-20-2017, 02:40 PM
gxnpt's Avatar
gxnpt gxnpt is offline
Contributing Member
 
Join Date: 09-10-16
Location: far west Florida near Destin
Posts: 104
iTrader: 0 / 0%
Quote:
Originally Posted by Rukbat View Post
I'd call the PHP code to read the spreadsheet directly fairly trivial too - but then, I'd been doing that for about 5 years before I retired. It was like sweeping the floor - boring, but it had to be done.
How long have you been retired? My last web development work was back in 2005 myself.

Yup - although there was one time for some refill inkjet sites where the data supplied by the front-end designer (I was subcontracting the code work) was in a weird format (commas and other non-alphanumerics in the data itself but not in a consistent manner - ended up using a spreadsheet for some fixes and a text editor for some and a couple quick scripts for some others depending on the issue and which was easier just to standardize the data - as if it had been mashed together from 4 different sources) and had to be fixed before even thinking about a script to put it in a database.

Quote:
Originally Posted by Rukbat View Post
Easy? Yes. Standard? Anything but. You don't mix M, V and C in a single file. Wait until you have a 50k file and you have to fix some little but - and you forgot to comment that section. Have Javascript call a dozen (or more) PHP files using AJAX and it's trivial. (You start planning for scaling from the start, not after you have to scrap the site and start over.)
Pay attention here. Everything he says is correct. Like all rules there are exceptions.
Things that are never intended to be large scale do not need to have that ability so long as they function within their intended environment.
You can have PHP generate Javascript just like it can generate HTML. It can also create new files containing generated PHP. A process may span multiple pages in sequence to reach a final result.

On the other hand, as he said, try to avoid things like the mess - a file directory - shown below.

The bulk of the first 3 is text (rules,intro,etc)
index.html 2016-09-04 17:07 32K game box (sysop.mod.player branches)
login.php 2016-09-04 17:06 36K players enter or join a war
main.php 2016-09-04 17:03 27K player game lobby
msg.php 2016-02-10 10:48 13K player chat/msg page
msginset.php 2016-02-17 14:25 1.6K iframe chat inset

tiny things
dbinfo.php 2016-02-15 12:44 519 -- the main database info
enter.php 2015-12-20 17:43 842
gametablesdone.php 2016-02-17 12:24 216
madegametables.php 2017-01-05 13:37 216
loggy.php 2015-12-20 17:28 886

script installation - sysop function
makegametables.php 2016-02-17 13:19 345K

game mod functions
mod.php 2015-12-26 06:29 7.0K
deletegame.php 2015-12-18 10:25 4.1K
newgame.php 2015-12-18 13:15 8.0K
newgame2x.php 2015-12-15 10:18 2.0K
newgame3x.php 2015-12-15 10:45 1.5K
resign.php 2015-12-19 14:02 4.0K
resignbymod.php 2015-12-18 09:02 5.3K

main map display and player interface page with the "varies depending on game phase" includes and readfiles
map.php 2016-12-26 23:29 57K
alliance.php 2015-10-02 09:09 5.9K
ally.php 2015-10-02 17:39 1.9K
build.php 2015-09-27 18:55 7.5K
combat.php 2015-11-29 17:58 6.1K
combatrep.php 2015-12-10 16:49 2.7K
command.php 2015-11-14 17:42 8.4K
constructed.php 2015-09-17 10:18 1.2K
exitnavi.php 2016-01-29 17:41 2.2K
hide.php 2015-09-28 14:48 4.8K
meadhall.php 2016-01-29 17:41 5.3K
navigation.php 2016-07-05 21:58 31K
navlog.php 2015-12-10 16:49 2.4K
nofight.php 2015-09-22 00:27 1.5K
nonavi.php 2015-09-17 10:21 1.5K
noterra.php 2015-11-10 18:55 1.5K
poly.php 2015-10-02 09:30 1.5K
repair.php 2015-10-11 15:17 27K
scrap.php 2015-09-28 14:48 5.6K
sensors.php 2015-09-23 20:58 3.2K
terra.php 2015-10-16 22:52 3.0K
terraform.php 2015-10-02 03:16 2.4K

transmitted order processing
mapaction.php 2016-02-11 14:09 5.0K -- hub for transmitted orders
dofight.php 2015-12-10 16:32 10K
newcombat.php 2016-02-11 14:09 5.6K
ownership.php 2016-02-11 14:26 15K
ownerstoboard.php 2015-12-10 16:32 2.6K
processmovement.php 2016-02-11 14:09 14K
transmitally.php 2016-01-29 17:41 7.6K
transmitbuilds.php 2016-01-29 17:41 6.6K
transmitfight.php 2016-01-29 17:41 4.0K
transmithides.php 2016-01-29 17:41 1.8K
transmitmoves.php 2016-01-29 17:41 8.6K
transmitrepairs.php 2016-01-29 17:41 3.1K
transmitscrap.php 2016-01-29 17:41 2.1K
transmitterra.php 2016-01-29 17:41 3.5K
updateboard.php 2015-12-10 16:32 2.6K

I am familiar ( a sad admission, I know ) with 50k + files lacking in documentation and comments -- modifying such messes is half of what I used to do freelance. But even when you CAN hold - for one brief shining moment - over 100k in your head at the same time only an idiot would set out planning on doing that.

That file list is - ignoring temporary files it creates for each war and images - my game. And my only excuse for doing it that way is that I was still working on the rules and it is a modular pieced together mutated several times things during development thing that was never expected to grow into a bloated single file like map.php became. I was working on a game design, not a coding design. I code like some people whittle.

Quote:
Originally Posted by Rukbat View Post
You just send the values to the server - don't include any data about the structure of the database.
Correct. And use POST vs GET for any values that need to stay hidden.
GET example URL
....ttp://thewebsitedomainname/play/map.php?gamename=For_the_Blog&me=cyan&mebe=4a8a08f 09d37b73795649038408b5f33
Quote:
Originally Posted by Rukbat View Post
Your method sounds like someone who just happened on an AJAX site, scanned a fw lines and knows how to send Javascript data to PHP - without understanding the whole reason for using AJAX. AJAX prevents all the problems you claim your "submit without submitting" trick does - a lot faster, with a lot less code and cleaner.
Study it for a few years, then see why it shouldn't be done your way. (Or go to Jackson, MS - there's a great programmer there who could explain AJAX to you in a week.)
Gee. Actually, I have never looked at an Ajax site. Brief history:
1968 Fortran II using IBM 1620 with card reader sorter etc. in high school
1970s stuck with a TRS-80 4k machine - a peculiarity in the level1 basic allowed making a hangman game despite a lack of string variables and manipulation since inputting a letter was treated as inputting the value assigned to that letter as a variable name
1980s C64/128 using Commodore Basic and 6502 assembly mainly -- only cracked one game myself during this time
1996 finally got a PC (Pentium 2 chip) and taught myself Javascript and PHP 3.3 (that was the version at the time) and MySQL and HTML4 -- these distracted me from learning Java and C++ but freelance web work paid for computer and internet
2005 - last freelance work I did - a content management and payment interface system - no further coding except for a couple off the cuff special purpose scripts for myself run as localhost and usually to automate something
2015 - retired - started playing around with my old 1978 microgame - a few new HTML5 methods and avoid some deprecated PHP but otherwise enough "tools in the workshop" for the prototype "computer generated boardgame"

So, while I had heard of Ajax it was in its infancy back when I was active. If I seriously take up coding again I may look into it (but might learn Java instead next).
I am not saying avoid Ajax. But we DID get some things done back in the olden days before it existed.
Quote:
Originally Posted by Rukbat View Post
Quote:
Having a page submit to itself is also a trick to get around the IE white flash on page load/reload - no flash when is a submit instead of a reload.
Neither is there a flash when Javascript sends data to a PP page and gets data in the AJAX callback - which is the whole reason for AJAX. If you submit a page - AJAX, PHP, anything else - you end the page and move on to the next one.
Without involving Ajax, the tacked on chat/msg function for my game uses an iframe. The code in the iframe originally reloaded every ten seconds - which was awful in IE.

The white flash prevention trick for page reload uses very little extra code.
text color:
black - unchanged
red - (commented) old line that is replaced
purple - new form and replacement line in code
Code:
<form action="msginset.php" name="dummy" id="dummy" target="chatty" method="post"></form> <script type="text/javascript"> function rebirth(){ //window.location.reload(); document.getElementById('dummy').submit() } myvar=setTimeout(rebirth, 10000); </script>

Quote:
Originally Posted by Rukbat View Post
Quote:
Page template has values substituted and is sent to browser.
PHP page sends data back to the browser - the browser formats the data, fits it to a template (usually not necessary - if there's that much data, it's probably faster to send the browser a new page).
That looks like a description of Ajax functionality. The old way was to have PHP read all needed values and perform any file functions before anything was sent to browser.
Quote:
Originally Posted by Rukbat View Post

Quote:
Values not displayed can be stored as Javascript values or plugged into hidden form fields for options belonging to a single item.
Or shouldn't have been sent (or requested) at all.
Some values not visible include select field items. With the PHP processing limited to before the browser gets anything, all variable values associated with an item are normally grabbed at the beginning.
Quote:
Originally Posted by Rukbat View Post

Quote:
Client-side:
When items are selected Javascript/CSS makes dynamic changes from options values and if a new item is selected makes the page submit info to itself.
NO!

The values are changed on the page itself, the page isn't submitted. Submission is the last thing a page does - it should close access to that page.
Options within an item do not submit. When selecting a new item causes a submit it is selecting a new page for that new item and loading a new set of potential values - but the same file that created the current page can create a new page by having a different value submitted to it or if there has been a change in some source data being read each time anything is submitted.
 
  #9  
Old 02-22-2017, 04:35 PM
Rukbat's Avatar
Rukbat Rukbat is offline
Contributing Member
 
Join Date: 08-08-11
Location: Long Island, NY, USA
Posts: 294
iTrader: 0 / 0%
Wow - lots of text.

Quote:
Originally Posted by gxnpt View Post
How long have you been retired? My last web development work was back in 2005 myself.
Since 2012. Not by choice - and the pain is still there.

Quote:
a weird format (commas and other non-alphanumerics in the data itself but not in a consistent manner - ended up using a spreadsheet for some fixes and a text editor for some and a couple quick scripts for some others depending on the issue and which was easier just to standardize the data - as if it had been mashed together from 4 different sources) and had to be fixed before even thinking about a script to put it in a database.
I found that copying grids from a web browser did some of that - Word and/or Excel, used very improperly, fixed a lot of it. (Especially if you were copying it from a .pdf document.)


Quote:
You can have PHP generate Javascript just like it can generate HTML. It can also create new files containing generated PHP. A process may span multiple pages in sequence to reach a final result.
Been all over there, done all of that.

Quote:
On the other hand, as he said, try to avoid things like the mess - a file directory - shown below.
I'd make a comment, but I'd have to wash my keyboard out with soap.

Quote:
I am familiar ( a sad admission, I know ) with 50k + files lacking in documentation and comments
A 1k file with nothing to let you know what the original programmer was thinking is bad enough.

What's worse, and I've had to work on them, is comments like

//this has to be completely replaced because, well, you know.

Or programs - yes, whole programs - that were full of pleonasms (for those not familiar with garbage masquerading as code:

if(!a != 5)
)

Or SQL transactions not within a transaction. Blow a file way down the list, and you might as well start restoring the entire 20GB database.

On my last job, I spent 7 years fixing that kind of stuff between writing actual programs.

Quote:
But even when you CAN hold - for one brief shining moment - over 100k in your head at the same time only an idiot would set out planning on doing that.
Or someone who grew up in programming where there was one printer in the building - and you'd better not even try to access it.

Quote:
it is a modular pieced together mutated several times things during development thing that was never expected to grow into a bloated single file like map.php became. I was working on a game design, not a coding design. I code like some people whittle.
I write in my sleep. When I wake up, I code it. But starting with "it's just a little bit of code" and letting it grow into a huge monster does lead to things like that "directory structure" (I hesitate to use the word "structure" - it's not structured. It can't be when you have to glue little pieces on all the time.)

Quote:
Correct. And use POST vs GET for any values that need to stay hidden.
AJAX sort of forces that.

Quote:
Gee. Actually, I have never looked at an Ajax site.
You may have. AJAX looks like Javascript in the client. It doesn't look much different from stock PHP in the server either. But if you've ever had a filled-out form submitted, then got a blank form back because you left out one little thing, that's not AJAX. AJAX would pop up an error message and let you just finish (or change) the form before submitting it again. And I'm sure you've been on a lot of those.

Quote:
Brief history:
1968 Fortran II using IBM 1620 with card reader sorter etc. in high school
Not until the 70s for me - then it was a 360 and a room full of card punches, stacks of cards, Hollerith tape, punches, erasers (punch all 5 or 8 holes), etc.

Quote:
1970s stuck with a TRS-80 4k machine - a peculiarity in the level1 basic allowed making a hangman game despite a lack of string variables and manipulation since inputting a letter was treated as inputting the value assigned to that letter as a variable name
1980 for me on a trash 80. Wrote educational games for 3 years. Commode 64, Apple ][, Ataris (400 and 800, IIRC) - and a bunch of programs to read the saved code on the Apple (which was the "develop on" machine), translate it into the bytecode for the target machine, then do the serial I/O to get it there.

Quote:
1980s C64/128 using Commodore Basic and 6502 assembly mainly
I loved that little beast. I wrote a 6502 version of CP/M so I could read my floppies into one.

Quote:
-- only cracked one game myself during this time
GRRR. I wrote software to prevent cracking. Like CP/M - with one user - \0xE5. Boot with your disk and the floppy was empty. Like starting every BASIC program at line 0 (blew a few interpreters). Like abort-formatting floppies on an IBM PC. Once you knew which sectors wouldn't read, you have a "this disk is a copy" list - bad sectors that could be read meant it was a copy. (You can't abort-format on a stock machine.)

Quote:
The white flash prevention trick for page reload uses very little extra code.
text color:
black - unchanged
red - (commented) old line that is replaced
purple - new form and replacement line in code
Code:
<form action="msginset.php" name="dummy" id="dummy" target="chatty" method="post"></form> <script type="text/javascript"> function rebirth(){ //window.location.reload(); document.getElementById('dummy').submit() } myvar=setTimeout(rebirth, 10000); </script>


That looks like a description of Ajax functionality. The old way was to have PHP read all needed values and perform any file functions before anything was sent to browser.
Redoing a page without refreshing it is AJAX. Now.

Quote:
Some values not visible include select field items. With the PHP processing limited to before the browser gets anything
Without using AJAX.

Quote:
all variable values associated with an item are normally grabbed at the beginning.
That's one reason I like AJAX. Grab any value (or modify it) at any time. Try grabbing 25 records from a 25 million record database (MySQL's LIMIT makes it trivial) and popping it into a grid that's already on the screen. And I mean 'pop'.

Quote:
Options within an item do not submit. When selecting a new item causes a submit it is selecting a new page for that new item and loading a new set of potential values - but the same file that created the current page can create a new page by having a different value submitted to it or if there has been a change in some source data being read each time anything is submitted.
Again - not standard AJAX. I had servers taking a page of data and sending me 1 character back. (Keep it off the internet - the computer is faster, so "x3" could put "Error in the address" on the screen - or it could replace the whole page, if needed.)

You bring back lots of memories. These days I just write little 5 line PHP files to do little things. I won't be tied to orders any more during this lifetime.
 
  #10  
Old 02-22-2017, 06:31 PM
gxnpt's Avatar
gxnpt gxnpt is offline
Contributing Member
 
Join Date: 09-10-16
Location: far west Florida near Destin
Posts: 104
iTrader: 0 / 0%
Now I am going to end up working and acquiring some docs and learning Ajax.

Just when I was rereading The Thousand Names prior to reading the next three books.

How am I going to catch up with my movie and tv collections?

I may fend it off briefly with HTML5 canvas stuff..............

I need longer days. Curse you,

May Thread fall directly on your Keep.
 
  #11  
Old 03-05-2017, 03:54 AM
michaelkeen michaelkeen is offline
Junior Member
 
Join Date: 03-04-17
Posts: 5
iTrader: 0 / 0%
You have a lot of guides on the web you can use.
If you are just getting started I recommend start slow because it can get complicated.
By working slowly you can detect your own code vulnerabilities and fix them.
If you are still having problems doing that you can get help from software for code security. I know one called checkamrx you can use.
Good luck anyway!
Michael.
 
Go Back   Webmaster Forum > Web Development > Coding Forum

Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Coding Newbie Question>Linking PHP in Dreamweaver? funlovinjane Coding Forum 4 12-29-2012 12:32 AM
Got an SEO + PHP coding question for you guys Iím thinking about for some time now. datentravel SEO Forum 1 08-12-2010 05:41 PM
Question on Javascript coding + Table help please! krypt Coding Forum 1 01-10-2008 12:55 AM
Coding Question scampy74 Coding Forum 8 02-20-2006 11:02 PM


V7N Network
Get exposure! V7N I Love Photography V7N SEO Blog V7N Directory


All times are GMT -7. The time now is 11:19 PM.
Powered by vBulletin
Copyright © 2000-2014 Jelsoft Enterprises Limited.
Copyright © 2003 - 2018 VIX-WomensForum LLC