473,406 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

New to PHP, Help needed

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.
Jul 17 '05 #1
2 1420
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" <xa****************@orbisuk.com> schrieb im Newsbeitrag
news:q4********************************@4ax.com...
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.

Jul 17 '05 #2
I must apologise to you all for my foolishness, I had forgotten to add
the "echo" command in front of my "mysql_result" command, that is why
the results did not appear in the table.

Once again sorry for wasting your time.
Xav

On Thu, 05 Aug 2004 09:52:10 +0100, Xavier Bourguignon
<xa****************@orbisuk.com> wrote:
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.


Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: System | last post by:
Hello All, Redhat 9.0 Mysql 3.23.56 ==> Running I want to upgarde to 4.0.13 but this is the error it says: # rpm -Uvh MySQL-server-4.0.13-0.i386.rpm warning: MySQL-server-4.0.13-0.i386.rpm: V3...
8
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
13
by: Joe Feldman | last post by:
This position is located in the South Bay Area in Northern California. If you are interested please send me your resume in a word .doc so that I can review it. If this does not look like a match,...
0
by: Cindy B | last post by:
Please send your resume and position to Cindy@AtlanticResource.com! I CAN NOT accept candidates that ARE OUTSIDE OF THE US! NO PHONE CALLS PLEASE! Email your resume to me! Position:SQL...
3
by: Wade | last post by:
I would like to install the .Net 1.1 framework on a Web Server running W2K to be able to run ASP.NET files, but I'm not sure where to find the files I need for the .Net framework. I have ".NET...
17
by: dingoatemydonut | last post by:
The C99 standard states: "In the abstract machine, all expressions are evaluated as specified by the semantics. An actual implementation need not evaluate part of an expression if it can deduce...
5
by: Steve | last post by:
Hi, I am sitting down to design our next set of internal apps. I would like to approach this in a way that would allow me to break logical parts of the application that handle specific tasks...
0
by: ultradiv | last post by:
I have a VB.NET application partly built that produces an xml output (just a file at present) I have a .NET webserver and SQLserver 2000 I need to be able to send the xml to the webserver/database...
28
by: Ian Davies | last post by:
Hello I would appreciate some help from someone who has knowledge of working with css, php javascript and how they interact. Ive been working on a task for the last few days and have started to...
37
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.