You are here: mysql_fetch_array for loop « PHP Programming Language « IT news, forums, messages
mysql_fetch_array for loop

Posted by alexbarham on 10/29/21 11:33

I am working on a script that queries a database and displays the
results as a line graph. Is there a way to loop through the results
using a for loop rather than the while loop? I have attached code that
just simply prints the values. I will worry about creating a graphic
afterwards:
<title>Database Test</title>
</head>
<body>
<?php
$connection = mysql_connect('mydb','user','pass');
mysql_error();
mysql_select_db('mytable',$connection);
$query = "SELECT date,symbol,close FROM stock_chart WHERE symbol='AA'";
$result = mysql_query($query,$connection);
$rowsfound = mysql_num_rows($result);
if($rowsfound > 0)
{
$count = 0;
while($row = mysql_fetch_array($result))
{
$close[$count] = $row['close'];
$count++;
}
}

for($i=0;$i<$rowsfound-1;$i++)
{
echo "Close $i is: $close[$i]<br/>";
$i_plus = $i + 1;
echo "Close $i_plus is: $close[$i_plus]<br/>";
}
mysql_close($connection);
?>
</body>
</html>

I have tried something like:
for($i=0;$i<rowsfound;$i++)
{
echo "Value is $row['close'][$i];
}
This didn't work.

Thanks for your help

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация