|
Posted by Miles Thompson on 07/31/05 04:26
You're talking about a table in a database, correct? Assuming the database
is MySQL, you would:
1. open a connection to the database
2. execute a SQL select statement to fetch the data
3. process the results, formatting them into HTML.
There are a number of tutorials on doing this, but it's only a few lines of
code:
1. Connect to the database:
require( "dbname.inc" ); //stores your hostname, username and password
outside the script.
$db = mysql_pconnect("$host", "$user", "$pass") or die("Unable to connect
to server");
2. Create your query, usually done by first assigning it to a variable.
That way, if you are not getting the results you want it's easy to echo the
SQL to the screen:
$sql = "SELECT month, day, value from sometable order by month, day"; //
use your own field names in place of month, etc.
$result = mysql_query($sql); // executes the SQL statement
//echo $result . . mysql_num_rows( $result) . "<br>";
3. test for and process the results. Here we assume a table displayed in
the user's browser.
if( $result && mysql_num_rows( $result) ){ //test that you have a result
AND that number of rows is > 0. Remember the convention that 0 is false.
while ($myrow = mysql_fetch_array($result)) {
//assuming you have issued a <table> somewhere above ...
echo "<tr> <td>" . $myrow['month'] . "</td>"; // the "." (dot)
concatenates in PHP
echo "<td> . $myrow['day'] . "</td>"; // or should we
say "joins strings and variables"
echo "<td> . $myrow['value'] . "</td> </tr>"; // and of course,
close the row
}
}
That's rudimentary. There is no WHERE condition on the SELECT which you
would use if you wanted a particular month or year.
Hope this has been helpful. Check out the various tutorials; there are
probably some written in Spanish. Go to:
http://www.php.net/links.php
and scroll down to Spanish, there are four links there.
Hope this has been helpful - Miles Thompson
At 02:38 PM 7/30/2005, Jesús Alain Rodríguez Santos wrote:
>Sorry for my english, i'm cuban, it's dificult for me explain that in
>english but I'll try:
>
> I have a table columns: month, day and value
>
>||month||day||value
> 7 1 56
> 7 3 34
> 8 4 50
> 9 5 78
> . . .
> . . .
>etc...
>
>I need to get the value for every day, for example:
>for day 1 the value is 56
>for day 3 the value is 67
>for day 4 the value is 50
>
>did you understain, please helpe me
>
>
>
>--
>Este mensaje ha sido analizado por MailScanner
>en busca de virus y otros contenidos peligrosos,
>y se considera que está limpio.
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, visit: http://www.php.net/unsub.php
[Back to original message]
|