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
https://forums.phpfreaks.com/topic/33053-increment-database-variable-values-help/
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...
I do not get exactly what you are trying to say, but when I put $i in the while loop it messes everything up. With the $i before the first while loop, I get the correct increments and everything, something is just wrong with my array, that is all.
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?
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]

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.