Jump to content

help:Outputting data from mysql database using php


uswege

Recommended Posts

I have just created a database for site created by someone else.

 

The address to the database is http://www.tib.co.tz/db

 

Use the following login details to get in

Username:  test

Password:  test

 

The Challenge is, i am trying to output data from the database (mysql databe) into a webpage using php script, but the script is just not working, where am getting it wrong? below is the output script i am using

 

<?php

include 'connect.php';

$query="SELECT * FROM main WHERE Category='Home' ORDER BY 'id' DESC Limit 1";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

$i=0;

while ($i < $num) {

$content=mysql_result($result,$i,"content");

echo "$content";

$i++;

}

?>

Thanks guys. . i think i am one step ahead.

 

I have removed mysql_close(); and changed  mysql_numrows => mysql_num_rows

 

before doing changes, the page could't open (the browser was just hanging and bringing an error msg), now the page opens but not data,  the connection is Successful only the data is not displayed.

 

The current script is

 

<?php

include 'connect.php';

$query="SELECT * FROM main WHERE category='Home' ORDER BY 'id' DESC Limit 1";

$result=mysql_query($query);

$num=mysql_num_rows($result);

$i=0;

while ($i < $num) {

$content=mysql_result($result,$i,"content");

echo "$content";

$i++;

}

?>

 

 

Also the DB address and login info is

http://www.tib.co.tz/db

Username:  test

Password:  test

 

May be it is something that has to do with the structure of my db.

i have two tables

1. main with fields id,category,content,updatetime,updateby

2.category with fields id,CategoryName

 

The category field in the main table is linked to the category table (because i want the category field in the main table to be dynamic)

 

i want to display the content field of a selected category field.

 

can any one help?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.