Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL,其中第一个字符是数字_Php_Mysqli - Fatal编程技术网

Php MySQL,其中第一个字符是数字

Php MySQL,其中第一个字符是数字,php,mysqli,Php,Mysqli,我有一个下拉列表: <form name="alphasearch" action="ialphalist.php" method="get"> <select style='font-size:26px;height:30px;width:540px;' name='alphasearch' onchange='this.form.submit()'> <option value="">Select the First letter of the Bu

我有一个下拉列表:

<form name="alphasearch" action="ialphalist.php" method="get">
<select style='font-size:26px;height:30px;width:540px;' name='alphasearch' onchange='this.form.submit()'>
   <option value="">Select the First letter of the Business Name</option>
   <option value="REGEXP'^[0-9]'">0-9</option>
   <option value="a%">A</option>
   <option value="b%">B</option>
   <option value="c%">C</option>
字母(A、B、C等)按预期显示结果,如果第一个字符是数字,我将尝试使其工作。我认为使用“REGEXP”语句应该是有效的,也许我的格式不对?我需要更改什么才能使其正常工作?

尝试以下操作:-

list($categoriesRecords, $categoriesMetaData) = getRecords(array(
    'tableName'   => 'categories',
    'perPage'     => '5',
    'loadUploads' => false,
    'allowSearch' => true,
    'where'       => "Bus_name REGEXP '^[a-zA-Z].*'",
    'orderBy'    => 'Bus_name',
编辑:通过网页指定标准

$regex = "'^".$_GET[alphasearch][0]."'";
    list($categoriesRecords, $categoriesMetaData) = getRecords(array(
        'tableName'   => 'categories',
        'perPage'     => '5',
        'loadUploads' => false,
        'allowSearch' => true,
        'where'       => "Bus_name REGEXP $regex",
        'orderBy'    => 'Bus_name',
这将得到所有以字母表(小或高)开头的总线名称

[a-zA-Z]=>字母表

.=>单个字符(数字、字母或其他任何字符)

.*=>第一个字母后面的字符可以是零或更多


希望有帮助。

您不能同时使用
LIKE
REGEX
。我可以用什么来代替Ignacio?一个或另一个。这样最终用户就可以通过网页指定搜索条件了吗?现在不要停下来,您只回答了一半问题。是的,请,这对字母有效,但对于任何以数字开头的记录,我在下拉列表中使用什么“选项值”呢?好的。对不起,如果我误解了你。如果在选项值中只使用[0-9]而不是REGEXP“^[0-9]”,那么我认为这会更好。将其更改为[0-9]后,可以在where条件下尝试此操作:-@dnevels$regex=$\u GET[alphasearch];“Bus_name REGEXP'^.$regex..*”或Bus_name LIKE'.$regex.'”;Sumit,谢谢你帮我做这件事。您是否在上面的$regex语句中出现语法错误或其他错误?当我现在选择字母或数字时,会出现一个空白屏幕。
$regex = "'^".$_GET[alphasearch][0]."'";
    list($categoriesRecords, $categoriesMetaData) = getRecords(array(
        'tableName'   => 'categories',
        'perPage'     => '5',
        'loadUploads' => false,
        'allowSearch' => true,
        'where'       => "Bus_name REGEXP $regex",
        'orderBy'    => 'Bus_name',