/    Sign up×
Community /Pin to ProfileBookmark

Urgent Help Needed for a Dummy

Ok I came up with a great idea to host our local dream team table on our website.

Instead of uploading the table as a htm file I decided we should generate the table server side from a database. I have managed to create a database and can update it but how do I create a php script to recreate the values in the table on the website.

I am an absolute dummy when it comes to php and dont really have the time to sit down and learn it now although I hope to pick it up along the way.

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@NogDogAug 26.2006 — What kind of database sysetm? If MySQL, take a look at the example on the [url=http://www.php.net/mysql_fetch_assoc]mysql_fetch_asssoc() manual page[/url].
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 26.2006 — Thanks, I have gone as far as I can and I get this

Could not successfully run query (SELECT id as POSITION, TEAM, TOTAL, WEEK, MONTH, OTHER FROM POSITION WHERE userstatus = 1) from DB: Unknown column 'id' in 'field list'
Copy linkTweet thisAlerts:
@NogDogAug 26.2006 — It's telling you that there is no column named "id" in table "DB". Check your spelling, including upper/lower case.
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 26.2006 — Ok, its succesfully pulling the information from the database and showing it but how to I format it back into a table?
Copy linkTweet thisAlerts:
@NogDogAug 26.2006 — Assuming you're looping on mysql_fetch_assoc:
[code=php]
echo "<table>n";
while($row = mysql_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row['POSITION']."</td>";
echo "<td>".$row['TEAM']."</td>";
// etc. for each column...
echo "</tr>n";
}
echo "</table>n";
[/code]
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 27.2006 — Thanks for your help

So far I have succesfully used this code


<?php

$conn = mysql_connect("localhost", "***database***", "***password***");

if (!$conn) {

echo "Unable to connect to DB: " . mysql_error();

exit;

}

if (!mysql_select_db("westlan_dreamteam")) {

echo "Unable to select mydbname: " . mysql_error();

exit;

}

function array2table($arr,$width)

{

$count = count($arr);

if($count > 0){

reset($arr);

$num = count(current($arr));

echo "<table align="center" border="2"cellpadding="1" cellspacing="0" width="$width">n";

echo "<tr>n";

foreach(current($arr) as $key => $value){

echo "<th>";

echo $key."&nbsp;";

echo "</th>n";


}


echo "</tr>n";

while ($curr_row = current($arr)) {

echo "<tr>n";

$col = 1;

while ($curr_field = current($curr_row)) {

echo "<td>";

echo $curr_field."&nbsp;";

echo "</td>n";

next($curr_row);

$col++;

}

while($col <= $num){

echo "<td>&nbsp;</td>n";

$col++;


}

echo "</tr>n";

next($arr);

}

echo "</table>n";

}

}


?>



<?

// Add DB connection script here

$query = "SELECT POS, TEAM, TOTAL, WEEK, MONTH, OTHER FROM POSITION";

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result)){

$array[] = $row; }

array2table($array,800); // Will output a table of 600px width

?>
[/quote]


to create this: http://www.westlandsclub.co.uk/dreamtable.php..

What I would liek to do now is colour in the table, is there I a way I can call a few lines at a time so I can set the background colour different, the table will always have 59 rows, for example can I say for row 1 - 5 have this background and text colour, 6 - 57 this background and this text colour and for row 58 have this background and this text colour?
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 28.2006 — Anyone please
Copy linkTweet thisAlerts:
@NogDogAug 28.2006 — Assign a class to the TR element, and define the background-color for it in your CSS style sheet/block. You'll need some sort of counter variable that you increment each loop, and add whatever logic you want to assign the appropriate class value to the TR based on the counter's value.
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 29.2006 — do you have an example for a thickie please
Copy linkTweet thisAlerts:
@ShaunJUKauthorAug 29.2006 — Oh alsoat the top of the table you will see I have put 'Last Updated: Week:'

what I want is data from the database in OTHER2 putting in here, so for example it would say 'Last Updated: 29/08/2006 Week 1 of 1 Month 1'

29/08/2006 , 1 of 1 , and Month 1 are all currently updated in the table where the league is taken from, how do I get this information in the above way?

Thanks in Advance

Shaun
×

Success!

Help @ShaunJUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...