Ask a Question related to PHP Development, Design and Development.
-
Micah Montoy #1
loop and write array
I'm having difficulty in trying to figure out a way to loop through a query
and extract the info from a single column into an array. Here is what I am
looking for. In the table, I have a column called keywords that has a
string of information that are separated with a comma. I am looking for a
way to extract each keyword from the one cell and make a conditional on it.
Otherwise its like this:
Column keywords has in a single cell - TV,television,HDTV,projection
I want to loop through each row cell in the column keywords and write out
each keyword to its own placement to be compared to what the user submits.
I was thinking of something like this but this is as far as I've gotten.
$search_string = $_POST["search"];
$search_string = strip_tags($search_string);
$search_string = strtolower($search_string);
$search_string = str_replace("\n", "", $search_string);
$search_string = strip_chars($search_string); //calls a formula which strips
specific chars
$search_string = str_replace(",", "", $search_string);
$search_string = explode(" ", $search_string);
$search_string = strip_words($search_string); //calls a formula which strips
specific words
$keywords = mssql_query("select keywords from category");
for ($i=0; i < mssql_num_rows($keywords); $i++) {
$keywords = mssql_result($keywords,0,"keywords"); //this will assign
the full string to the variable keywords
if ($keywords == $search_string){
echo ("keyword $keywords found");
}
}
I can't figure out how to separate each keyword by the comma and then write
that specific keyword to an array to be used. Any and all help would be
appreciated.
thanks
Micah Montoy Guest
-
loop through array to build a new array
If I combine the following 2 functions (accesses by clicking a checkbox), as result the new array does not contains all items that matches the... -
cannot loop the array
I have 2 questions regarding arrays: 1) we need to define the size of the array, there is no dynamic array concept? i.e. the following define the... -
Array Loop
Please help me to debug: <cfquery name="qSelectPwd" datasource="#Application.AppDSN#"> select password from tablename </cfquery> <!---... -
array data matches but array created in loop doesn't work
I have the exact same data in two arrays, but only the array created like so will work: $spaw_imglibs = array( array( 'value' =>... -
Write a loop
Would you show me how I can write this as a loop? #Get the number of files uploaded my $Num_Files = 0; if ($size_file > 1) { $Num_Files = 1; }...



Reply With Quote

