$sqlquery="SELECT adress from table where (ID=(SELECT ID from table1 where micro REGEXP '[[:<:]]".$name."[[:>:]]'))or($name='')"
$result=mysql_query($sqlquery);
while($data=mysql_fetch_array($result))
{...}
Because it gives me an error when I try this.The error is :
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result.
Clearly the sql query is not correct but why?
The regex is correct,tryed it elsewhere.Also tryed ID IN instead of ID=(select ...
Last edited by sebs on Fri Oct 28, 2005 6:38 am, edited 1 time in total.
With mysql_error gives this:
You have an error in your SQL syntax near 'select firme.ID from firme where (firme.micro REGEXP '[[:<:]]a' at line 1
I don't know what could mean.Yes I think my version of mysql supports subqueries.
$query = mysql_query("SELECT ID from table1 where micro REGEXP '[[:<:]]".$name."[[:>:]]'))or($name='')");
$IDs = array();
while($rs = mysql_fetch_row())
$IDs[] = $rs[0];
$query = mysql_query("SELECT adress from table where ID IN (".join(',', $IDs).")");
//do whatever with $query result...
edit: oops, too late & yeah... use d11's version... that's much better
Inner join does not help me so much because it's too slow.I make the same number of comparison as if I the second table had it's fields in the first table.
sebs wrote:Inner join does not help me so much because it's too slow.I make the same number of comparison as if I the second table had it's fields in the first table.
Inner Joins are generally fast, left joins can be slow but anyway... If you don't want to use a join then it probably won't add much in this instance to just use two queries, the first to get ID, the second uses that ID in the query.