Immortal55 Posted January 6, 2007 Share Posted January 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 rest your $i inside the while loop.[code]<?phpif ($result) { while ($tablefield = mysql_fetch_array($result, MYSQL_ASSOC)) { $i = 0; // move him down......?>[/code] Quote Link to comment Share on other sites More sharing options...
Immortal55 Posted January 6, 2007 Author Share Posted January 6, 2007 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... Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 if you don't reset $i, then your while ($i < $numReturn) will not loop past the first while ($tablefield = mysql_fetch_assoc Quote Link to comment Share on other sites More sharing options...
Immortal55 Posted January 6, 2007 Author Share Posted January 6, 2007 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. Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 Don't know, dude. I must not be understanding what the script is supposed to do. Quote Link to comment Share on other sites More sharing options...
Immortal55 Posted January 6, 2007 Author Share Posted January 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 6, 2007 Share Posted January 6, 2007 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.