_spaz Posted September 23, 2009 Share Posted September 23, 2009 Hi, Hoping someone can help me out... I'm new to PHP and im trying to figure out how to store results from each result found in a loop to a seperate variable so that I can call upon them individually at a later time. echo "<table cellpadding='1' border='1' bgcolor='#FFFFDF' bordercolor='#E8B900' align='center' > <tr> <th>ID</th> <th>FileName</th> <th>Create Time</th> <th>Start Time</th> <th>End Time</th> <th>Progress</th> </tr>"; $result_row = mysql_fetch_row(($result)); { echo "<tr>"; echo "<td>" . $result_row[0] . "</td>"; echo "<td>" . $result_row[1] . "</td>"; echo "<td>" . $result_row[2] . "</td>"; echo "<td>" . $result_row[3] . "</td>"; echo "<td>" . $result_row[4] . "</td>"; echo "<td>" . $result_row[5] . "</td>"; echo "</tr>"; } echo "</table>"; if ($result_row[6] > "") { $i=0; echo "<br><b>Alerts Found:</b><br><br>"; while ($i < $num) { $id=mysql_result($result,$i,"id"); $alert=mysql_result($result,$i,"alert"); $location=mysql_result($result,$i,"location"); echo "$id -$alert @ $location<br><br>"; <<<-------------Store this result to a variable $i++; } } else { echo "<br><br>No Alerts Found for this Asset"; } Any help would be appreciated.... Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/ Share on other sites More sharing options...
ozestretch Posted September 23, 2009 Share Posted September 23, 2009 you might find this post helpful http://www.phpfreaks.com/forums/index.php/topic,270046.0.html Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923327 Share on other sites More sharing options...
_spaz Posted September 23, 2009 Author Share Posted September 23, 2009 you might find this post helpful http://www.phpfreaks.com/forums/index.php/topic,270046.0.html I took a look and can't really seem to find a solution from there, maybe im not looking at it right Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923486 Share on other sites More sharing options...
cahrehn Posted September 23, 2009 Share Posted September 23, 2009 Before you do, if ($result_row[6] > "") { make an array, $alerts = array(); and at the same place that you echo, $alerts[] = "$id -$alert @ $location<br><br>"; This will automatically increment the index of the array and build it during the loop. Double check afterward with: print_r($alerts); Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923556 Share on other sites More sharing options...
_spaz Posted September 23, 2009 Author Share Posted September 23, 2009 Before you do, if ($result_row[6] > "") { make an array, $alerts = array(); and at the same place that you echo, $alerts[] = "$id -$alert @ $location<br><br>"; This will automatically increment the index of the array and build it during the loop. Double check afterward with: print_r($alerts); Thanks, that's great, now how do i extract specific values from a specific array, say $array[2] for instance? Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923657 Share on other sites More sharing options...
knsito Posted September 23, 2009 Share Posted September 23, 2009 Thanks, that's great, now how do i extract specific values from a specific array, say $array[2] for instance? You just did it.. $array[2], will be the data in the array at #2 so if $array[2] had the data "Hello World" and you did echo $array[2]; Would display "Hello World" Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923675 Share on other sites More sharing options...
_spaz Posted September 23, 2009 Author Share Posted September 23, 2009 Thanks, that's great, now how do i extract specific values from a specific array, say $array[2] for instance? You just did it.. $array[2], will be the data in the array at #2 so if $array[2] had the data "Hello World" and you did echo $array[2]; Would display "Hello World" There are three variables in the array[2] "$id $alert $location" maybe I have to make the array see them as different values? Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923723 Share on other sites More sharing options...
ozestretch Posted September 24, 2009 Share Posted September 24, 2009 $array[] = 'oZestretch hates microsoft'; $newarrary = explode(" ",$array[0]); // where " " (a space) is the deliminator echo $newarray[0].' really, really '.$newarray[1].' all software by '.$newarray[2]; // prints oZestretch really, really hates all software by microsoft Use it in a loop or what ever you like the methods used in that post are how you can do same, I was short on time when I read your post so took a lazy way out Link to comment https://forums.phpfreaks.com/topic/175181-store-vaiables-within-a-loop/#findComment-923984 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.