Skip to main content
deleted 11 characters in body
Source Link
Krzysiek Dróżdż
  • 25.5k
  • 9
  • 53
  • 74

I have this working statement for searching a single column in my database:

$foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, sodium FROM foodsTable WHERE namevariations like %s", "%$search_text%"), ARRAY_A ); 

I would like to include another column in the search called "foodname" but I can't seem to figure out the correct syntax.

How should I formulate my prepare statement so that I'm searching "namevariations" OR "foodname" and a match in either column will select that row?

Thanks!

I have this working statement for searching a single column in my database:

$foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, sodium FROM foodsTable WHERE namevariations like %s", "%$search_text%"), ARRAY_A ); 

I would like to include another column in the search called "foodname" but I can't seem to figure out the correct syntax.

How should I formulate my prepare statement so that I'm searching "namevariations" OR "foodname" and a match in either column will select that row?

Thanks!

I have this working statement for searching a single column in my database:

$foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, sodium FROM foodsTable WHERE namevariations like %s", "%$search_text%"), ARRAY_A ); 

I would like to include another column in the search called "foodname" but I can't seem to figure out the correct syntax.

How should I formulate my prepare statement so that I'm searching "namevariations" OR "foodname" and a match in either column will select that row?

Source Link

Syntax for $wpdb->prepare when searching in two columns

I have this working statement for searching a single column in my database:

$foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, sodium FROM foodsTable WHERE namevariations like %s", "%$search_text%"), ARRAY_A ); 

I would like to include another column in the search called "foodname" but I can't seem to figure out the correct syntax.

How should I formulate my prepare statement so that I'm searching "namevariations" OR "foodname" and a match in either column will select that row?

Thanks!