Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Wild Card on Values / Numbers

New Here ,
Nov 30, 2009 Nov 30, 2009

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

TOPICS
Server side applications
594
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 01, 2009 Dec 01, 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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 03, 2009 Dec 03, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines