470,848 Members | 1,801 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Problem displaying mysql records:

Hello,

I wondered if anyone could offer some guidance, I trying to write a
php script to connect to a database, and display the records in a
table.

I found the code here in a php4 text, and when I run this directly
through the php intrupeter, the line Successfully connected is display
and 4 as the number of rows.

The database table we connect to, has three field username, firstname,
surname.

When I tried a while loop, to display the data in a table. No values
were displayed.

Could anyone possibly demonstrate how to display the username,
firstname, surname values in a basic table?

Thank you
<?php
function db_connect(){
global $MYSQL_ERRNO, $MYSQL_ERROR;

$link_id = mysql_connect("localhost","user04", "password04");

if(!$link_id){
$MYSQL_ERROR = "Connection failed";
return 0;
}
else if(empty($dbname) && !mysql_select_db("database04")){
$MYSQL_ERROR = mysql_error();
return 0;
} else return $link_id;
}

!$link_id = db_connect();
if(!$link_id) die(error_message('Error connecting'));

$result = mysql_query("SELECT * FROM users");
if(!$result) error_message('Error in selection');
else echo "Successfully connected. ";

$query_data = mysql_fetch_array($result);
$total_records = $query_data[0];

if(!$total_records) error_message('No records');
else echo "$total_records.";
?>
Jul 17 '05 #1
5 1787
Antoni wrote:
Hello,

I wondered if anyone could offer some guidance, I trying to write a
php script to connect to a database, and display the records in a
table.

I found the code here in a php4 text, and when I run this directly
through the php intrupeter, the line Successfully connected is display
and 4 as the number of rows.

The database table we connect to, has three field username, firstname,
surname.

When I tried a while loop, to display the data in a table. No values
were displayed.

Could anyone possibly demonstrate how to display the username,
firstname, surname values in a basic table?

Thank you
<?php
function db_connect(){
global $MYSQL_ERRNO, $MYSQL_ERROR;

$link_id = mysql_connect("localhost","user04", "password04");

if(!$link_id){
$MYSQL_ERROR = "Connection failed";
return 0;
}
else if(empty($dbname) && !mysql_select_db("database04")){
$MYSQL_ERROR = mysql_error();
return 0;
} else return $link_id;
}

!$link_id = db_connect();
if(!$link_id) die(error_message('Error connecting'));

$result = mysql_query("SELECT * FROM users");
if(!$result) error_message('Error in selection');
else echo "Successfully connected. ";

$query_data = mysql_fetch_array($result);
$total_records = $query_data[0];

if(!$total_records) error_message('No records');
else echo "$total_records.";
?>


try:

while ($query_data = mysql_fetch_array($result)) {
echo $query_data['username'].'|'.$query_data['firstname'].
'|'.$query_data['surname'] ;
}

sadara
Jul 17 '05 #2
Thank you for replying.

I managed to display the mysql data in a table.

I resolved this by providing the position of each data item in the
rows, such as $query_data[0];

My php version did not seems to like $query_data["username"];

Anyway its working now.
Jul 17 '05 #3
Thank you for replying.

I managed to display the mysql data in a table.

I resolved this by providing the position of each data item in the
rows, such as $query_data[0];

My php version did not seems to like $query_data["username"];

Anyway its working now.
Jul 17 '05 #4
Thank you for replying.

I managed to display the mysql data in a table.

I resolved this by providing the position of each data item in the
rows, such as $query_data[0];

My php version did not seems to like $query_data["username"];

Anyway its working now.
Jul 17 '05 #5
Thank you for replying.

I managed to display the mysql data in a table.

I resolved this by providing the position of each data item in the
rows, such as $query_data[0];

My php version did not seems to like $query_data["username"];

Anyway its working now.
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by david | last post: by
reply views Thread by sanjay gupta | last post: by
13 posts views Thread by comp.lang.php | last post: by
3 posts views Thread by mikec87 | last post: by
10 posts views Thread by Lloyd Harold | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.