Skip to main content
Known Participant
November 30, 2009
Question

Wild Card on Values / Numbers

  • November 30, 2009
  • 2 replies
  • 584 views

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);

This topic has been closed for replies.

2 replies

Inspiring
December 3, 2009

I prefer to do that in the SQL (Recordset).

So have your initail code as DW default, i.e

$colname_rs_grd = "-1";
if (isset($_POST['id_grade'])) {
  $colname_rs_grd = $_POST['id_grade'];

and set the value of your All Groups option to -1 in design view (All Groups would be the label)

Then, include this somewhere in your Where clause:

WHERE ...  AND (t_gh_dash1.GRD=colname OR colname=-1)

[if you've used DW to create the recordset code you'll have wrapped in a sprintf() so will also have

GetSQLValueString($colname_rs_grd, "int") in there somewhere.

That way you don't need to use a wildcard at all, and DW will still recognise your recordset.

Ed

Waleed Barakat
Known Participant
December 1, 2009

Hi, Try to read this article, i found it useful and may help!

http://www.tizag.com/mysqlTutorial/mysqlwhere.php

__
Best Regards
Waleed Barakat
Developer-Online Creator and programmer