You are here: Re: comment pls on how i take data from the database.. « PHP Programming Language « IT news, forums, messages
Re: comment pls on how i take data from the database..

Posted by Schraalhans Keukenmeester on 05/22/07 06:36

At Mon, 21 May 2007 19:32:41 -0700, shotokan99 let his monkeys type:

> as of now im using this approach to take data:
> =====================================
> require('conn.php');
> $q='select * from '.$dbf_vid.' order by xrank';
> $res=mysql_query($q) or die('error: cannot perform query on new');
> $num=mysql_numrows($res);
> $i=0;
>
> while($i<$num){
> $id=mysql_result($res,$i,'xid');
> $rank=mysql_result($res,$i,'xrank');
> $title=mysql_result($res,$i,'xtitle');
> $artist=mysql_result($res,$i,'xartist');
> $taglink=mysql_result($res,$i,'xtaglink');
> $img=mysql_result($res,$i,'ximg');
> $ref=mysql_result($res,$i,'xref');
> $swf=mysql_result($res,$i,'xswf');
>
> if($i%2==0){
> $color='#BCBCDE';
> $i++;
> }else{
> $color='#FFFFFF';
> $i++;
> }
> echo'<tr>';
> echo' <td bgcolor="'.$color.'" width="33"><font face="Verdana"
> size="1">'.$id.'</font></td>';
> echo' <td bgcolor="'.$color.'" width="28"><font face="Verdana"
> size="1">'.$rank.'</font></td>';
> echo' <td bgcolor="'.$color.'" width="183"><font face="Verdana"
> size="1">'.$title.'</font></td>';
> echo' <td bgcolor="'.$color.'" width="213"><font face="Verdana"
> size="1">'.$artist.'</font></td>';
> echo' <td bgcolor="'.$color.'" width="110"><font face="Verdana"
> size="1">'.$ref.'</font></td>';
> echo' <td bgcolor="'.$color.'" width="54"><font face="Verdana"
> size="1">
> <a href="mtvdel.php?id='.$id.'&dbf=mtv_topvid_ph">delete</
> a></font></td>';
> echo' <td bgcolor="'.$color.'" width="53"><font face="Verdana"
> size="1"><a href="mtvedit.php?
> id='.$id.'
> &rank='.$rank.'
> &title='.$title.'
> &by='.$artist.'
> &taglink='.$taglink.'
> &ref='.$ref.'
> &img='.$img.'
> &swf='.$swf.'
> ">edit</a></font></td>';
> echo' </tr>';
> }//end while
>
> ==================================
> this works fine with me, but is there much better approach compared to
> what im doing?
>
> tnx

[...]
if (mysql_numrows($res) === 0) {
// do_something when no rows found
// and exit
}
while ($row = mysql_fetch_assoc($res)) {
// your html here, replace your var names with
// $row['fieldname'] (e.g. $row['title'])
}

All the quotes can make things confusing. Consider using heredoc syntax
instead, then you only have to worry about quotes you actually need in the
html.

echo <<<HTML_END
<td bgcolor="$row['color']" width="33">
<font face="Verdana" size="1">$row['id']</font>
</td>';
(etc etc)
HTML_END; // no spaces before this line, just the heredoc endtag and a ;


HTH
Sh.

 

Navigation:

[Reply to this 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

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