Jump to content

Store Vaiables within a loop


_spaz

Recommended Posts

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

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);

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?

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"

 

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?

$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  :shrug:

 

 

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.