Jump to content

Recommended Posts

Hi

 

 

 

Can anyone explain how to use a wildcard in a query when I am retrieving numbers / values.

 

 

 

I have a select that has options: All, 1 2 3 4

 

 

 

If user chooses All I want my query to bring back records where 1,2,3,4 are included else bring back just the number chosen

 

 

 

I have tried % and it doesnt work.

 

 

 

Here is my section of code: I need the 0 in the first section to be % effectively.

 

 

 

Any help appreciated

 

 

 

$colname_rs_grd = 0;

if (isset($_POST['id_grade'])) {

        if ($_POST['id_grade'] == "All Grades") {

      $colname_rs_grd = 0;

              }else {

  $colname_rs_grd = $_POST['id_grade'];

}

 

 

 

mysql_select_db($database_dashboard, $dashboard);

$query_rs_tbl1 = "SELECT t_gh_dash1.`WeekDay`, 'RaceCount' AS Category, Count(distinct t_gh_dash1.RaceID) as RaceCount FROM t_gh_dash1 WHERE t_gh_dash1.Pool Like  '$colname_rs_pool' AND t_gh_dash1.GRD = '$colname_rs_grd' AND t_gh_dash1.trk Like '$colname_rs_trk' GROUP BY t_gh_dash1.`WeekDay`";

 

 

$rs_tbl1 = mysql_query($query_rs_tbl1, $dashboard) or die(mysql_error());

$row_rs_tbl1 = mysql_fetch_assoc($rs_tbl1);

$totalRows_rs_tbl1 = mysql_num_rows($rs_tbl1);

Link to comment
https://forums.phpfreaks.com/topic/183488-wild-card-on-values-numbers/
Share on other sites

Hi and thanks

 

I can see how that would work - however my example list of 1 2 3 4 is not a fixed list so setting $colname_rs_grd to be 1,2,3,4 dosnt work - in reality the numbers are dynamic and maybe 11,456,223,etc and there maybe 10 of them or 1000?

 

Not sure why I can't wile card numbers like using # or ?

 

Any other thoughts?

 

Simon

Hi

Sorry if my explanation is confusing.

 

I have a select box on my page and the user chooses either "All Values" or one of the integers in the select box. The values could be any number as they are pulled from a database.

 

I then want to build a query which uses the value chosen above in the where statement.

 

Select * Where t_gh_dash1.GRD = $colname_rs_grd.

 

This works if the user chooses an integer but if I dont know how to write the query to work if the user chooses "All Values".

 

Is it possible to write an IF statement withing my query string do basically exclude that where command if the user chooses "All Values"?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.