MySQL Wildcard

MySQL Wildcard

am 07.05.2010 10:46:31 von Karl DeSaulniers

--Apple-Mail-7-709531489
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed

Hello All,
What I want to do is get all the fields from a table without
specifying which ID to grab from.
I am trying to implement a wildcard in my query. What am I doing
wrong? I keep getting...

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource"

CODE:::::

function getOptGrps($ID){
if ($ID == "All") {
$ID = "%"; // % = MySQL multi character wildcard
}
$q = "SELECT * FROM ".OPT_GRPS_TABLE." WHERE OptGrpID LIKE
'$ID' ";
$result = $this->query($q);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$array_results = mysql_fetch_array($result);
return $array_results;
}

AND this does not work either

function getOptGrps(){
$q = "SELECT * FROM ".OPT_GRPS_TABLE;
$result = $this->query($q);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$array_results = mysql_fetch_array($result);
return $array_results;
}

TIA,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--Apple-Mail-7-709531489--

Re: MySQL Wildcard

am 07.05.2010 11:16:14 von Onur Yerlikaya

function getOptGrps($ID=null){
if ($ID == "All") {
$ID = "%"; // % = MySQL multi character wildcard
}
$extraClause = "";
if(!is_null($ID))
{
$extraClause = " WHERE OptGrpID LIKE '$ID' ";
}
$q = "SELECT * FROM ".OPT_GRPS_TABLE.$extraClause;
$result = $this->query($q);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$array_results = mysql_fetch_array($result);
return $array_results;
}



On May 7, 2010, at 11:46 AM, Karl DeSaulniers wrote:

> ...

--
Onur Yerlikaya




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: MySQL Wildcard

am 07.05.2010 11:36:56 von Karl DeSaulniers

On May 7, 2010, at 4:16 AM, Onur Yerlikaya wrote:

> function getOptGrps($ID=null){
> if ($ID == "All") {
> $ID = "%"; // % = MySQL multi character wildcard
> }
> $extraClause = "";
> if(!is_null($ID))
> {
> $extraClause = " WHERE OptGrpID LIKE '$ID' ";
> }
> $q = "SELECT * FROM ".OPT_GRPS_TABLE.$extraClause;
> $result = $this->query($q);
> /* Error occurred, return given name by default */
> if(!$result || (mysql_numrows($result) < 1)){
> return NULL;
> }
> /* Return result array */
> $array_results = mysql_fetch_array($result);
> return $array_results;
> }
>
>
>
> On May 7, 2010, at 11:46 AM, Karl DeSaulniers wrote:
>
>> ...
>
> --
> Onur Yerlikaya

Thanks Onur, but same error message.
It is not setting the % as a wild card.
Not sure the way around this.


Karl

>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: MySQL Wildcard

am 07.05.2010 11:40:38 von Onur Yerlikaya

so sorry

function getOptGrps($ID=null){
$extraClause = "";
if($ID != "All")
{
$extraClause = " WHERE OptGrpID LIKE '$ID' ";
}
$q = "SELECT * FROM ".OPT_GRPS_TABLE.$extraClause;
$result = $this->query($q);
/* Error occurred, return given name by default */
if(!$result || (mysql_numrows($result) < 1)){
return NULL;
}
/* Return result array */
$array_results = mysql_fetch_array($result);
return $array_results;
}


On May 7, 2010, at 12:36 PM, Karl DeSaulniers wrote:

>
> On May 7, 2010, at 4:16 AM, Onur Yerlikaya wrote:
>
>> function getOptGrps($ID=null){
>> if ($ID == "All") {
>> $ID = "%"; // % = MySQL multi character wildcard
>> }
>> $extraClause = "";
>> if(!is_null($ID))
>> {
>> $extraClause = " WHERE OptGrpID LIKE '$ID' ";
>> }
>> $q = "SELECT * FROM ".OPT_GRPS_TABLE.$extraClause;
>> $result = $this->query($q);
>> /* Error occurred, return given name by default */
>> if(!$result || (mysql_numrows($result) < 1)){
>> return NULL;
>> }
>> /* Return result array */
>> $array_results = mysql_fetch_array($result);
>> return $array_results;
>> }
>>
>>
>>
>> On May 7, 2010, at 11:46 AM, Karl DeSaulniers wrote:
>>
>>> ...
>>
>> --
>> Onur Yerlikaya
>
> Thanks Onur, but same error message.
> It is not setting the % as a wild card.
> Not sure the way around this.
>
>
> Karl
>
>>
>>
>>
>>
>> --
>> PHP Database Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>
> Karl DeSaulniers
> Design Drumm
> http://designdrumm.com
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

--
Onur Yerlikaya




--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: MySQL Wildcard

am 08.05.2010 06:59:53 von David Robley

Karl DeSaulniers wrote:

> Hello All,
> What I want to do is get all the fields from a table without
> specifying which ID to grab from.
> I am trying to implement a wildcard in my query. What am I doing
> wrong? I keep getting...
>
> "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
> result resource"
>
> CODE:::::
>
> function getOptGrps($ID){
> if ($ID == "All") {
> $ID = "%"; // % = MySQL multi character wildcard
> }
> $q = "SELECT * FROM ".OPT_GRPS_TABLE." WHERE OptGrpID LIKE
> '$ID' ";
> $result = $this->query($q);
> /* Error occurred, return given name by default */
> if(!$result || (mysql_numrows($result) < 1)){
> return NULL;
> }
> /* Return result array */
> $array_results = mysql_fetch_array($result);
> return $array_results;
> }
>
> AND this does not work either
>
> function getOptGrps(){
> $q = "SELECT * FROM ".OPT_GRPS_TABLE;
> $result = $this->query($q);
> /* Error occurred, return given name by default */
> if(!$result || (mysql_numrows($result) < 1)){
> return NULL;
> }
> /* Return result array */
> $array_results = mysql_fetch_array($result);
> return $array_results;
> }
>
> TIA,

Well, I'd hazard a guess that OPT_GRPS_TABLE may not be what you think it
is; in any case, the first step in debugging would be to echo your query $q
and see what it really contains. And does the class that handles your db
query have an error reporting function? If so, try using it.

Note that to retrieve all records, you could skip the WHERE, or use WHERE 1

Cheers
--
David Robley

Machine-independent: does not run on any existing machine.
Today is Pungenday, the 55th day of Discord in the YOLD 3176.


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php