PDA

View Full Version : Flash & PHP news system: query error



free mojo
February 24th, 2005, 07:11 AM
Hello, I have been following this tutorial:
http://sephiroth.it/tutorials/flashPHP/news/index.php

I keep recieving a query error everytime i try to test it. I am a PHP beginner. I do not know for sure how i should be connecting to my server/host. I have been trying to do this kind of thing for about 6 months and i can't work out how to connect etc. I really would be grateful of some help.

Here's my code: (NB. My database is called "freemojo_news", my table "news" and my fields "id", "news" and "date")


<?
$database = "freemojo_news";

$connection = mysql_connect ("localhost","","") or die ("Sorry, server error!");

mysql_select_db($database);

$query = "SELECT * FROM news ORDER BY date ASC";

$result = mysql_query($query) or die ("Sorry, query error!");
$num_rows = mysql_num_rows($result);

for($i=0;$i<$num_rows;$i++){
$row = mysql_fetch_array($result);

$news = "news$i";
$news = $row['news'];

$date = "date$i";
$date = $row['date'];

print("&news$i=$news");
print("&date$i=$date");

}
mysql_close($connection);

?>

If anyone can help i would appreciate it.
I am using phpmyadmin to create the database.

Thanks!
Andrew

Chaoswarp
February 24th, 2005, 11:43 AM
$connection = mysql_connect ("localhost","","") or die ("Sorry, server error!");

No UserName or Password for the database?

hl
February 24th, 2005, 11:50 AM
your going to need that username and password.

binime
February 24th, 2005, 12:55 PM
he may have not added them in here for security issues? ah who knows


$query = "SELECT * FROM news ORDER BY date ASC";

$result = mysql_query($query)
while($row = mysql_fetch_array($result)) {

$news = "news$i";
$news = $row['news'];

$date = "date$i";
$date = $row['date'];

print("&news$i=$news");
print("&date$i=$date");

}

CyanBlue
February 24th, 2005, 10:45 PM
I'd do this first just to make sure... :)
Go to the phpMyAdmin site and do the query there to see if you are getting the data...

free mojo
February 25th, 2005, 06:52 AM
I've resolved it now. Using this code with help from another forum too:


<?
$database = "freemojo_news";
$connection = mysql_connect ("localhost","username","password") or die ("Sorry, connection to server failed!");

mysql_select_db($database, $connection);


$query = "SELECT * FROM `news` ORDER BY date ASC";
$result = mysql_query($query) or die ("Sorry, query error!");


while($row = mysql_fetch_array($result)){


$news = "news".$i;
$news = $row['news'];

$date = "date".$i;
$date = $row['date'];

print("&news".$i."=".$news);
print("&date".$i."=".$date);
}
mysql_close($connection);

?>


The really annoying problem now is that i can't get the flash side right. Data from the database is loading into my textfield fine but i want it to display the different fields in a certain order all in the same text field.

e.g There are 3 fields in my database:
id (auto-increment) , news, date

I want each news article to be displayed in order of the newest 10, displayed with data from the date field above the data from the news field, then the second newest news article displayed in the same format below that and so on.

If anyone can help me to achieve that i would be very greatful. It's very frustrating but probably really simple. My AS code looks like this:



stop();
_root.scrollBar.target = news;
news.htmlText = "Loading php";
newsData = new LoadVars();
newsData.load("php/getdata.php");
newsData.onLoad = function(done) {
if (done) {
news.htmlText = this.news;
}
};


I have some other plans that all depend on how the data loads in too for the working and updating of the gig listings. If anyone has any idea how this would be done please say so.

Andrew