RE: [PHP-DB] DB CODEING HELP!!!!!
| From: | Rich Gray | Date: | Sun, 23 Mar 2003 21:41:21 +0000 |
| Subject: | RE: [PHP-DB] DB CODEING HELP!!!!! | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-26573@lists.php.net to get a copy of this message | ||
> this is bugging me. I have tried everything and I cant develop
> the code without an error. Can someone plese write me simple code
> that will go through a table and print 3 collums of that table? I
> cant figure it out
I don't know which database you're using but say for example it was MySQL
here's a very quick and dirty example ....
<?
$link = mysql_connect('localhost','user','password') or
die(mysql_error());
if (mysql_select_db('mydatabase',$link)) {
$rs = mysql_query('select col1, col2, col3 from mytable') or die
(mysql_error());
$num = mysql_num_rows($rs);
for ($i=0;$i<$num;$i++) {
$row = mysql_fetch_assoc($rs);
echo 'Col 1: '.$row['col1'].' Col 2: '.$row['col2'].'
Col 3:
'.$row['col3'].'<br />';
}
}
mysql_close($link);
?>