By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,637 Members | 3,079 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,637 IT Pros & Developers. It's quick & easy.

How do I externally update a table in my htm file?

w33nie
P: 56
I really have no idea where to start for this, as i'm VERY new to scripting, but i do have intermediate skills at html, so i thought i'd try and get a nudge in the right direction from a help site.

I'm currently making a website where I'll need to have a rankings table of teams for an online computer game league.
I'll put this table in my .htm file, as I want it to be integrated in the page, and look just like a regular table would.
but, I want to be able to externally update the data in this table, so I don't have to change the .htm file after every match, updating the teams, their positions on the table and the rest of the data.

the primary aim of this method for me, is for ease of use.
i would also like this external file to be able to sort the positions of teams on the table for me, based on the points this team has won.

so, does anyone know of a format of file or external source i could use? like PHP or another script?
and how i would achieve this goal.


cheers.
rowan.
Jan 18 '07 #1
Share this Question
Share on Google+
16 Replies


Expert 100+
P: 1,892
What do you have available PHP,ASP, etc... I'm going to move this thread to the appropriate forum.
Jan 18 '07 #2

w33nie
P: 56
umm, ive got mySQL and PHP4/PHP5 available to use in the hosting plan, but i just lack any knowledge of coding in them.

which one do you think would be more appropriate? for the basic aims i'm trying to achieve.
Jan 18 '07 #3

Expert 100+
P: 1,892
PHP4/PHP5 are the versions the main thing is that you can run PHP on your site. I'm going to move this thread to the PHP forum.
Jan 18 '07 #4

ronverdonk
Expert 2.5K+
P: 4,258
First you have to make a choice between storing the data in a flat text file or in a MySQL database.

Both solutions can be externally updated via a grid script and both can be read, sorted and stored into your html page.

MySQL is easier to handle and program, but has more server overhead. A flat file is more difficult (column positions etc.) to program but has less overhead.

So it's up to you to first decide how and where you want your data to be stored.

Ronald :cool:
Jan 18 '07 #5

w33nie
P: 56
well i think as a complete beginner i should use mySQL, if its easier.
i'll only need a maximum of 72 text fields in the table, so there shouldn't be too much server overhead, right?

so if i'm to use mySQL, could you point me to a decent tutorial for integrating it into a table in html?
i havent downloaded mySQL though, and havent a clue what to do once i have got it, anyway.

thanks for all the help in advance.
Jan 18 '07 #6

w33nie
P: 56
thanks.
well... currently, im on the freewebmasterhelp tutorial.
i've downloaded mySQL, gotten an account, and am trying to set up phpMyAdmin, but the setup.php file won't open in IE or firefox... and i need it to. otherwise i cant use phpMyAdmin.

what do you suggest i do?
Jan 18 '07 #8

ronverdonk
Expert 2.5K+
P: 4,258
I'd suggest that you forget about phpMyAdmin for now and setup your MySQL server first using the command line interface. You'll learn more about Mysql and the SQL statements using that. If not, you can also execute SQL via a server script, like PHP.

First get your server setup right, then worry about the user interface like phpMyAdmin.

Ronald :cool:
Jan 19 '07 #9

w33nie
P: 56
well i really have no idea what i'm doing, and the server won't set up properly.

so, the other option, a flat text file.
how do i integrate that with my html file, and will it allow automatic sorting based on the information in the flat text file?
Jan 19 '07 #10

Atli
Expert 5K+
P: 5,058
Hi there

I have another, extreeemly simple solution, wich I far from being as good as anything using any form of a database.

In your html file Im assuming you have a table and that you want to add a tr row to the end of it before you close it?

If so you could add a html comment before you close the table and have a php file replace the comment with a new row.

Wich could be done somewhat like this...
[PHP]// Read the file
$filePath = "myhtml.html";
$fh = fopen($filePath, "r");
$contents = fread($fh, filesize($filePath));
fclose($fh);

// Change the contents
$newRow = "
\n<tr> <td> Somedata </td><td>". $_POST['fieldname'] ."</td></tr>
\n<!-- what? -->";
$output = str_replace("<!-- what? -->", $newRow, $contents);

// Overwrite the file with new content
$fh = fopen($filePath, "w");
fwrite($fh, $output);
fclose($fh);[/PHP]

This php code would be the target of a html <form> wich would provide the <input> field named 'fieldname'.
You would obviously have to edit to $newRow variable in the PHP to create the output you need, and create the html form that would call the php.

Hope this helps you :)
Jan 19 '07 #11

w33nie
P: 56
thanks for the help, but, haha, i dont think u realise how much of a beginner i am.
because i don't understand that.
but i do want a database solution, something that will allow sorting and mathematical problems in it.

so im trying to get mySQL working again, ill keep trying, and hopefully i'll get it in the end.

ill post again if i run into any problems.
Jan 19 '07 #12

Atli
Expert 5K+
P: 5,058
I see :P

I think MySQL comes with a ms installer so it really should be no problem.

This here is a file I created for myself, instructions on how to manually install PHP on Apache server with MySQL.

How to manualy install PHP on Apache server with MySQL with Win XP

Note: this is based on a rather old version but should work fine tho
Jan 19 '07 #13

w33nie
P: 56
well finally i've managed to get it working for the most part,
but how do I sort the table by a variable?

i can sort it in phpmyadmin, but once i put it in the .php file, its no longer sorted
Feb 6 '07 #14

ronverdonk
Expert 2.5K+
P: 4,258
In order to answer that you must show the PHP and the MySQL code you use to extract the data from the db.

Ronald :cool:
Feb 6 '07 #15

w33nie
P: 56
well here's the code in my .php file.

Expand|Select|Wrap|Line Numbers
  1. <? $hostname = "p3smysql17.secureserver.net"; // The mySQL DB server. 
  2. $username = "acssl_table"; // The username you created for this database. 
  3. $password = "Victoria3"; // The password you created for the username. 
  4. $usertable = "table"; // The name of the table you made. 
  5. $dbName = "acssl_table"; // This is the name of the database you made. 
  6.  
  7. MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable");
  8. @mysql_select_db( "$dbName") or die( "Unable to select database"); 
  9. ?> 
  10. <? 
  11. //error message (not found message)begins 
  12. $XX = "No Record Found, to search again please close this window"; 
  13. //query details table begins
  14. $query = mysql_query("SELECT * FROM `table` LIMIT 0, 30 "); 
  15. while ($row = @mysql_fetch_array($query)) 
  16. $variable1=$row["team"];
  17. $variable2=$row["played"]; 
  18. $variable3=$row["won"]; 
  19. $variable4=$row["drawn"];
  20. $variable5=$row["lost"];
  21. $variable6=$row["for"]; 
  22. $variable7=$row["against"]; 
  23. $variable8=$row["difference"]; 
  24. $variable9=$row["points"];
  25. //table layout for results 
  26.  
  27. print ("<tr>");
  28. print ("<td width='150'><span class='BodyTable'>$variable1</span></td>");
  29. print ("<td width='50' align='center'><span class='BodyTable'>$variable2</span></td>");
  30. print ("<td width='50' align='center'><span class='BodyTable'>$variable3</span></td>");
  31. print ("<td width='50' align='center'><span class='BodyTable'>$variable4</span></td>");
  32. print ("<td width='50' align='center'><span class='BodyTable'>$variable5</span></td>");
  33. print ("<td width='50' align='center'><span class='BodyTable'>$variable6</span></td>");
  34. print ("<td width='50' align='center'><span class='BodyTable'>$variable7</span></td>");
  35. print ("<td width='75' align='center'><span class='BodyTable'>$variable8</span></td>");
  36. print ("<td width='75' align='center'><span class='BodyTable'>$variable9</span></td>");
  37. print ("</tr>"); 
  38. }
  39. //below this is the function for no record!!
  40. if (!$variable1)
  41. print ("$XX");
  42. //end 
  43. ?>
and these are screenshots of the database,
didnt think theyd be useful, but I really don't know what you're looking for, so:

here's one of the table

and one of the data
Feb 7 '07 #16

w33nie
P: 56
oh, and could someone explain how to do that in phpMyAdmin 2.7
Feb 8 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.