Jump to content

[SOLVED] Problem using an array value in a SQL WHERE clause.


scott.stephan

Recommended Posts

I have a function I pass an array to do some stuff with. Here's the array initialization, plus the clause giving me trouble:

 

if($type == 'acknowledge' || $type == 'view'){
    $table_name[0]="new_batch";
    $table_name[1]="bol_new";
    $table_name[2]="lots_new";
}

bol_display($table_name, $curr_po_num);

 

And here's what gives me a problem:

 

 $queryall="SELECT * FROM $T_NAMES[0] WHERE po_num='$curr_po_num'";
    $result=mysql_query($queryall) or die(mysql_error());

 

And the error:

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '] WHERE po_num='777MCLANE'' at line 1

 

If I change it to

$queryall="SELECT * FROM '$T_NAMES[0]' WHERE po_num='$curr_po_num'";

, I get

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''new_batch' WHERE po_num='777MCLANE'' at line 1

 

It looks like I'm getting an extra " ' " in there. Any idea where? What's my goof here?

Problem solved. It was a different, similar clause:

 

$querybol="SELECT * FROM $T_NAMES[1]] WHERE po_num='$curr_po_num'";

 

Where I had an extra goofy bracket. I swear, I struggle with these things for like 40 minutes, post ot here and then solve it 30 seconds later. Is there some kind of ESP stuff going on?

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.