Jump to content

Increment Database variable values! HELP!


Immortal55

Recommended Posts

I have this script here, and it is grabbing the information from my database table, and assigning them to values. The problem is my value is set to 3 for every value....

Here is the script:

[code]
if ($result) {
    $i = 0;
    while ($tablefield = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $id = $tablefield['id'];
        $Name = $tablefield['title'];
        $Author = $tablefield['author'];
        $TheDate = $tablefield['date'];
        $TextData = $tablefield['story'];

$numReturn = count($tablefield);

while ($i < $numReturn) {
        $Name        = $Name;
        $TextData    = $TextData;
        $Author      = $Author;
        $TheDate      = $TheDate;
        print "&";
        print "Name$i=$Name&TextData$i=$TextData&Author$i=$Author&TheDate$i=$TheDate";
        $i++;
}
    }
    $numItems = mysql_num_rows($result);
    print "&NumItems=$numReturn&Go=Yes&";
}
[/code]

this exports this:

[b]&Name3=Test1&TextData3=Hello, this is a story that hopefully will be called into flash!&Author3=Mitch&TheDate3=today&Name3=Test2&TextData3=Well, this is coming from the future......Yeah.&Author3=John&TheDate3=tomorrow&Name3=Test8000&TextData3=ZUBBLE CUBBLE MUBBLE SHUBBLE&Author3=Toby&TheDate3=June 5th, 3030&NumItems=3[/b]

Notice how all the actual number values are set to 3, which I have 3 inputs in the database, so it is counting right, but it's assigning it to every one.... I want the variables going up incrementally (i.e. Name1=Test1 .... Name2=Test2...)

What is the problem. Thank you in Advance.
Link to comment
Share on other sites

I am sorry, but I believe doing that would just reset $i to 0, which is not what I want at all.... I have a new problem though...

It is with my array, the array is not getting my results. Here is the script:

[code]
$i=0;
while ($tablefield = mysql_fetch_assoc($result) && $numm = mysql_num_rows($result)) {
        $id[$i] = $row['id'];
        $title[$i] = $row['title'];
        $author[$i] = $row['author'];
        $thedate[$i] = $row['date'];
        $text[$i] = $row['story'];


$numReturn = $numm;

while ($i < $numReturn) {

        $Name        = $title[$i];
        $TextData    = $text[$i];
        $Author      = $author[$i];
        $TheDate      = $thedate[$i];
        print "&";
        print "Name$i=$Name&TextData$i=$TextData&Author$i=$Author&TheDate$i=$TheDate";
        $i++;
    }}
[/code]

everything is working fine, except nothing has any values from the database, which makes me think that the array is not working for some reason....Thanks for the help...
Link to comment
Share on other sites

What I want this script to do is take values from my database and assign them to the numerous variables that the array creates, so if the script worked it would output this:

&Name0=[b]NAME[/b]&TextData0=[b]TEXT[/b]&Author0=[b]AUTHOR[/b]&TheDate0=[b]DATE[/b]&Name1=[b]NAME[/b]&TextData1=[b]TEXT[/b]&Author1=[b]AUTHOR[/b]&TheDate1=[b]DATE[/b]&Name2=[b]NAME[/b]&TextData2=[b]TEXT[/b]&Author2=[b]AUTHOR[/b]&TheDate2=[b]DATE[/b]&NumItems=3&Go=Yes&


I just bolded the values to show you that I want them to say something. All I am getting as output right now is this:

&Name0=&TextData0=&Author0=&TheDate0=&Name1=&TextData1=&Author1=&TheDate1=&Name2=&TextData2=&Author2=&TheDate2=&NumItems=3&Go=Yes&



See, no values.

My DB has 3 records in it, so the final NumItems is correct, but why is nothing else getting any values?
Link to comment
Share on other sites

would this work?

[code=php:0]<?
if ($result) {
    $i = 0;
    while ($tablefield = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $id = $tablefield['id'];
        $Name = $tablefield['title'];
        $Author = $tablefield['author'];
        $TheDate = $tablefield['date'];
        $TextData = $tablefield['story'];
        print "&";
        print "Name$i=$Name&TextData$i=$TextData&Author$i=$Author&TheDate$i=$TheDate";
        $i++;
    }
    $numItems = mysql_num_rows($result);
    print "&NumItems=$numItems&Go=Yes&";
}
?>[/code]
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.