Jump to content

PHP, table continually repeats information!


Immortal55

Recommended Posts

Alright, I am doing a little dynamic loading in flash, and I am trying to load the variables from a PHP script. I make an array based on the entries in the table, and then they are passed on to flash....The only thing is is that my script grabs the same story multiple times.....and sometimes in a nonsense order....

Here is the script:

[code]
mysql_connect('localhost','admin','iffy')
or die ('Could not connect to database');
mysql_select_db('whitedevil')
or die ('Yeah, your database was found, but not the tables!');

$result = mysql_query('SELECT * FROM news') or die ('no query');

if ($result) {
while ($tablefield = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $tablefield['id'];
$title = $tablefield['title'];
$author = $tablefield['author'];
$date = $tablefield['date'];
$text = $tablefield['story'];

$numReturn = count($tablefield);
$i = 0;
print "&";

    while ($i < $numReturn) {
        $Name        = $title;
        $TextData    = $text;
$Author   = $author;
$TheDate      = $date;

        print "Name$i=$Name&TextData$i=$TextData&Author$i=$Author&TheDate$i=TheDate&";
        $i++;
    }
print "&NumItems=$numReturn&Go=Yes&";
}}

else {
print('Sorry, no work.');
}
[/code]

now what would be doing that?? Thank you in advance!
Link to comment
Share on other sites

I altered the code a little bit.....but now it only shows the most recently added entry in the database, but only once.

here it is:

[code]
if ($result) {
while ($tablefield = mysql_fetch_array($result, MYSQL_ASSOC)) {
$id = $tablefield['id'];
$title = $tablefield['title'];
$author = $tablefield['author'];
$thedate = $tablefield['date'];
$text = $tablefield['story'];
}


$numReturn = count($tablefield);
$i = 0;

    while ($i < $numReturn) {
        $Name        = $title;
        $TextData    = $text;
$Author   = $author;
$TheDate      = $thedate;

print "&";
        print "Name$i=$Name&TextData$i=$TextData&Author$i=$Author&TheDate$i=$TheDate";

        $i++;
    }print "&NumItems=$numReturn&Go=Yes&";
}
[/code]

Help appreciated! Thank you!
Link to comment
Share on other sites

Immortal, I think your problems will go away when you fix your indentation.  Make sure every "while", every "if" and every "for" has a closing brace underneath it in the same column.

In your latest code, the closing brace for your while loop is in the wrong column.  This makes it unclear that the while loop finishes too early.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.