Answered
Can I loop a sql query???
Hi,
I have an array that has x number of values. I want to run a sql statement x number of times using the next array value each time.
Basically I have a recordset that displays results based on a search. The result of the search is a list of names, the trouble is for reasons beyond my control the names are in a single db field as "FirstLast". I want to take this value and match it up to another table that has the first and last names in separate fields. So far I have extracted the results from the first recordset using a while loop, the resulting array is called $name_search :
mysql_select_db($database_nancy, $nancy);
$query_search = "SELECT artist FROM images WHERE caption LIKE '%$keyword%' OR piece_name LIKE '%$keyword%' OR show_title LIKE '%$keyword%' GROUP BY artist";
$search = mysql_query($query_search, $nancy) or die(mysql_error());
$totalRows_search = mysql_num_rows($search);
$name_search = array();
while(list($artist) = mysql_fetch_row($search)) {
$name_search[] = $artist;
}
I now want to take the values of the $name_search array and run a SELECT statement on table2 for each value and display the results. Could a foreach loop handle that ? Using php/mysql
I have an array that has x number of values. I want to run a sql statement x number of times using the next array value each time.
Basically I have a recordset that displays results based on a search. The result of the search is a list of names, the trouble is for reasons beyond my control the names are in a single db field as "FirstLast". I want to take this value and match it up to another table that has the first and last names in separate fields. So far I have extracted the results from the first recordset using a while loop, the resulting array is called $name_search :
mysql_select_db($database_nancy, $nancy);
$query_search = "SELECT artist FROM images WHERE caption LIKE '%$keyword%' OR piece_name LIKE '%$keyword%' OR show_title LIKE '%$keyword%' GROUP BY artist";
$search = mysql_query($query_search, $nancy) or die(mysql_error());
$totalRows_search = mysql_num_rows($search);
$name_search = array();
while(list($artist) = mysql_fetch_row($search)) {
$name_search[] = $artist;
}
I now want to take the values of the $name_search array and run a SELECT statement on table2 for each value and display the results. Could a foreach loop handle that ? Using php/mysql
