loop error
Posted: Sat Jan 23, 2010 3:03 pm
I am having an issue with the second While Loop in the code below:
Here is the output of the $sql variable:
SELECT pages.idpages.categorypages.price, pages.idpages.categorypages.price FROM pages WHERE id ="1"
Here is what I want it to be:
SELECT pages.id, pages.category, pages.price FROM pages WHERE id ="1"
any ideas why it's looping three times on each pass?
Here is the output of the $sql variable:
SELECT pages.idpages.categorypages.price, pages.idpages.categorypages.price FROM pages WHERE id ="1"
Here is what I want it to be:
SELECT pages.id, pages.category, pages.price FROM pages WHERE id ="1"
any ideas why it's looping three times on each pass?
Code: Select all
$tarray = array(1);
$fields = array('id', 'category', 'price');
$number = count($tarray);
$fnumber = count($fields);
$a = 0;
while ($a < $number)
{
$sql ='SELECT ';
$b=0;
while ($b < $fnumber)
{
if ($fields[$b] = 'id')
{
$sql .= 'pages.id';
}
if ($fields[$b] = 'category')
{
$sql .= 'pages.category';
}
if ($fields[$b] = 'price')
{
$sql .= 'pages.price';
}
if ($b < --$fnumber)
{
$sql .= ', ';
}
else
{
$sql .= ' ';
}
++$b;
}
$sql .= 'FROM pages WHERE id ="' . $tarray[$a] . '";';
++$a;
}
echo $sql;