flyersun Posted January 19, 2008 Share Posted January 19, 2008 When I started writing this script it sounded pretty simple but I've run into a few problems. The script some information from a database and then a loop is used to put the information into variables. What I want is for each time the loop is run it outputs different variables so that these variables can then be used later on in the script. So for example at the moment each time it goes around a different value is assigned to $data1 etc but I want it to create a new variable to put the data into instead of just writing over the old one. $querydata = "SELECT * FROM tblgraphdata WHERE graphID ='1'"; $resultsdata = mysql_query($querydata) or die ("Problem with query:" . mysql_error()); $rowsdata = mysql_num_rows($resultsdata); $i = 0; while ($i < $rowsdata){ $data1 = mysql_result($resultsdata, $i, "data1"); $data2 = mysql_result($resultsdata, $i, "data2"); $data3 = mysql_result($resultsdata, $i, "data3"); $data4 = mysql_result($resultsdata, $i, "data4"); $color = mysql_result($resultsdata, $i, "color"); $i ++; } Any ideas? Thank you soo much for helping! Quote Link to comment https://forums.phpfreaks.com/topic/86825-solved-looping-problem/ Share on other sites More sharing options...
wildteen88 Posted January 20, 2008 Share Posted January 20, 2008 You'll find it easier if you use mysql_fetch_assoc rather than mysql_result: $querydata = "SELECT data1, data2, data3, data4, color FROM tblgraphdata WHERE graphID ='1'"; $resultsdata = mysql_query($querydata) or die ("Problem with query:" . mysql_error()); while ($row = mysql_fetch_assoc($resultsdata)) { $rowdata[] = $row; // add returned results from $row intop $rowdata array. } echo '<pre>' . print_r($rowdata, true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/86825-solved-looping-problem/#findComment-444429 Share on other sites More sharing options...
Fyorl Posted January 20, 2008 Share Posted January 20, 2008 I think an array might be your answer. Quote Link to comment https://forums.phpfreaks.com/topic/86825-solved-looping-problem/#findComment-444430 Share on other sites More sharing options...
flyersun Posted January 21, 2008 Author Share Posted January 21, 2008 Thank you soo much Quote Link to comment https://forums.phpfreaks.com/topic/86825-solved-looping-problem/#findComment-445518 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.