| re: New to PHP, Help needed
Hi Xavier,
first you should set "localhost" in connotation marks when using
mysql_connect.
Second:
Type the code like this:
....
<body>
<?php
$user="photos_user";
$password="t0rt01se";
$database="photos_db";
$conn_id = mysql_connect("localhost",$user,$password);
mysql_select_db($database);
$query="SELECT name, description, disporder FROM tCategory WHERE displayed =
'Y' ORDER BY disporder";
$result=mysql_query($query,$conn_id);
while($res_x = mysql_fetch_row($result))
{
echo "$res_x[0] $res_x[1] $res_x[2] <br>"; //these are the three
selected columns in the select-phrase!
}
mysql_close($conn_id);
</body>
....
Maybe this can help you a little bit.
Kind regards
Tim
"Xavier Bourguignon" <xavier.bourguignon@orbisuk.com> schrieb im Newsbeitrag
news:q4t3h091c796k9sqcamngdt7pdsu9gmhuj@4ax.com...[color=blue]
> Hi, I am new to PHP and I am having a little problem displaying data
> taken from the mysql database running on my server.
>
> The code below shows a html (php) page which is supposed to display
> the result of a query, I have a feeling that I am not using PHP
> properly to display the data, can you let me know what you think?
>
> <HTML>
> <HEAD>
> <TITLE> Admin Category Show </TITLE>
> <META NAME="Author" CONTENT="Xavier Bourguignon">
> <META NAME="Keywords" CONTENT="photos">
> </HEAD>
>
> <BODY>
> <?php
> $user="photos_user";
> $password="t0rt01se";
> $database="photos_db";
>
> mysql_connect(localhost,$user,$password);
> @mysql_select_db($database) or die( "Unable to
> select database");
>
> $query="SELECT name, description, disporder
> FROM tCategory WHERE displayed = 'Y' ORDER BY disporder";
> $result=mysql_query($query);
> $num=mysql_numrows($result);
> mysql_close();
>
> $i=0;
> ?>
>
> <TABLE BORDER="1" CELLSPACING="5" CELLPADDING="2"
> BGCOLOR="#CCCCCC">
> <TR>
> <TH>
> Category Name
> </TH>
> <TH>
> Category Description
> </TH>
> </TR>
> <?php while ($i < $num) { ?>
> <TR>
> <TD>
> <?php
> mysql_result($result,$i,"name"); ?>
> </TD>
> <TD>
> <?php
> mysql_result($result,$i,"description"); ?>
> </TD>
> </TR>
> <?php $i++; } ?>
> </TABLE>
> </BODY>
> </HTML>
>
>
>
> Thanks in advance for the help.
>
>[/color] |