Reply to Re: Question about displaying MySQLl data

Your name:

Reply:


Posted by Jerry Stuckle on 06/14/07 17:55

L C wrote:
> "Iván Sánchez Ortega" <ivansanchez-alg@rroba-escomposlinux.-.punto.-.org>
> wrote in message news:f4rloi$1b4$1@hercules.cohp1...
>> L C wrote:
>>
>>> I am outputting tables. The stuff I am doing is for a golf league. If
> I
>>> output scores it comes out like this.
>> Loop through the results (RTFM!), outputting "<table>", "<tr>" and "<td>"
>> where appropiate.
>>
>> --
>> ----------------------------------
>> Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-
>>
>> http://acm.asoc.fi.upm.es/~mr/
>> Proudly running Debian Linux with 2.6.20-1-amd64 kernel, KDE 3.5.7, and
> PHP
>> 5.2.3-1 generating this signature.
>> Uptime: 17:12:19 up 13 days, 23:14, 3 users, load average: 3.50, 2.67,
>> 2.03
>>
>
> RTFM?
>
> Loop through the results (RTFM!), outputting "<table>", "<tr>" and "<td>"
> where appropiate
>
> Like This?
>
> echo "<table border='1'><tr>";
> // printing table headers
> for($i=0;
> $i<$fields_num; $i++){ $field = mysql_fetch_field($result);
> echo "<td>{$field->name}</td>";}echo "</tr>\n";
> // printing table rows
> while($row = mysql_fetch_row($result)){ echo "<tr>";
> // $row is array... foreach( .. ) puts every element
> // of $row to $cell variable
> foreach($row as $cell)
> echo "<td>$cell</td>";
> echo "</tr>\n";
> }
> mysql_free_result($result);
> ?>
> </body></html>
>
> I have RTFMed my way to this point. A week ago I didn't have PHP, MySQL, or
> IIS installed on my system. I didn't ask some generic question like: "How
> do I get PHP". I asked what I thought was a relatively specific question
> after searching the web for answers. I did search for PHP, MySQL, and
> format. I got many hits about date formats. Unfortunately, unlike you, I
> wasn't born knowing everything, I had to ask questions along the way. I am
> sorry I bothered you with my question.
>
>
>

Yes, that's the right idea, although you can clean it up a little, i.e.

echo "<table border='1'><tr>";
// printing table headers

for($i=0; $i<$fields_num; $i++){
$field = mysql_fetch_field($result);
echo "<td>{$field->name}</td>";
}
echo "</tr>\n";

// printing table rows
while($row = mysql_fetch_row($result)){
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
echo "</tr>\n";
}
mysql_free_result($result);
?>

And yes, when you're new it's sometimes hard to get a handle on what you
need. I'd suggest visiting the bookstore and getting a decent book on
PHP and MySQl. While you're at it, you could look for one on HTML if
you feel a need.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация