MySQL query in a function
Posted: Fri May 21, 2010 8:39 am
Hi Guys,
I'm trying to put together a function to replace a MySQL Stored procedure. But I keep getting 'parse errors'.
The code I have so far is:
but it doesn't work, can anyone see what I have missed (or even if this would work at all).
Basically the idea is it selects a random colour from the colours table, and then updates the squares table at ID "1". It then does the same again for ID "2" and so on until it has filled all the way up to ID "25". And then it stops.
I'm trying to put together a function to replace a MySQL Stored procedure. But I keep getting 'parse errors'.
The code I have so far is:
Code: Select all
function BasicSquares($a)
{
While($a<26) {
$query1 = mysql_query("SELECT colour FROM db1.colours ORDER BY RAND() LIMIT 1");
$colour = mysql_fetch_array($query1);
$query2 = mysql_query( "Update db1.Squares set colour =".$colour['colour']."WHERE id =".$a." )";
$a=$a+1;
}
}
BasicSquares("1");
Basically the idea is it selects a random colour from the colours table, and then updates the squares table at ID "1". It then does the same again for ID "2" and so on until it has filled all the way up to ID "25". And then it stops.