PDA

View Full Version : PHP/Mysql select statement problems.


a_kerbouchard
02-09-2006, 11:57 PM
When I run my query, and I echo my query it looks like it should work. The resulting echo'd statement would say something like, "Select * FROM Product Where Price=10 AND Name=Test". If I select any of my six columns which values are passed to the query it doesn't work (except when I select the first column). The first column does work and it happens to be an integer column. I wonder if the VarChar columns are the culprit? Here is a sample of my code.

require_once ('mysql_conn2.php');

for ($row=0; $row <= 5; $row++)
{
for ($row; $arr[$row]=="Left-Blank" && $row <= 5; $row++)
{
echo $row;
}

if ($x != 1)
{
$queryAll3 = "SELECT * FROM Product WHERE";
$queryAll3 .= " ";
$queryAll3 .= "$arrvar[$row]";
$queryAll3 .= "=";
$queryAll3 .= "$arr[$row]";
$x=1;
}
elseif ($row <=5)
{
$queryAll3 .= " ";
$queryAll3 .= "AND";
$queryAll3 .= " ";
$queryAll3 .= "$arrvar[$row]";
$queryAll3 .= "=";
$queryAll3 .= "$arr[$row]";

}

}

$resultAll3 = @mysql_query ($queryAll3);

$num = mysql_num_rows ($resultAll3);

GJay
02-10-2006, 12:15 AM
You need to enclose string variables in quotes in your query.

a_kerbouchard
02-10-2006, 02:27 AM
Thanks, that fixed it (single quotes).

$'queryAll3 .= "$arr[$row]' ";