Home > Archive > PHP Language > September 2006 > rowcount = 0 when using substr
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
rowcount = 0 when using substr
|
|
|
| Hi,
I dont know what I am doing wrong - but when I substr a variable then my
mysql returns no results.
eg (msisdn is +445621458 for example:)
$searchnum = substr($msisdn, 3);
mysql_connect("localhost",$MysqlName,$MysqlPW);
$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
datesent >= '$yesterdaysdate' AND number LIKE '%$searchnum'";
$Results = MySQL($dbName,$Selectstr);
$RowCount = mysql_num_rows($Results);
....Rowcount returns a 0 value,
If I do this, I get results:
$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
datesent >= '$yesterdaysdate' AND number LIKE '%5621458'";
What am I doing wrong?
| |
|
| On Tue, 19 Sep 2006 18:08:28 +0200, "tony" <tda_silva@nospam.hotmail.com> wrote:
>Hi,
>
>I dont know what I am doing wrong - but when I substr a variable then my
>mysql returns no results.
>
>eg (msisdn is +445621458 for example:)
>$searchnum = substr($msisdn, 3);
>mysql_connect("localhost",$MysqlName,$MysqlPW);
>$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
>datesent >= '$yesterdaysdate' AND number LIKE '%$searchnum'";
>$Results = MySQL($dbName,$Selectstr);
>$RowCount = mysql_num_rows($Results);
>
>...Rowcount returns a 0 value,
>
>If I do this, I get results:
>
>$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
>datesent >= '$yesterdaysdate' AND number LIKE '%5621458'";
>
>What am I doing wrong?
>
I think + might be causing an issue
first validate that msisdn is a string and echos correct value
if you know that is true then echo out the $searchum var make sure it's 5621458
substr might be weird with +
| |
|
| Hi,
I do echo out msisdn and searchnum and I get the correct value.
If I do echo strlen($searchnum) it returns 18
So are there some hidden characters that do not show when echo ?
To test, I did this
echo ".......".$searchnum.".....";
and I would get
.........5621458.........
That is only 7 characters - so why does strlen return a value of 18 ?
If it does return a value of 18, then that might be why my mysql query is
not working ?
"Gleep" <Gleep@Gleep.com> wrote in message
news:f4g0h253o6iq5eqbkk9af6ih8ecq4mcc9d@
4ax.com...
> On Tue, 19 Sep 2006 18:08:28 +0200, "tony" <tda_silva@nospam.hotmail.com>
wrote:
>
>
>
> I think + might be causing an issue
> first validate that msisdn is a string and echos correct value
> if you know that is true then echo out the $searchum var make sure
it's 5621458
> substr might be weird with +
>
| |
|
| On Tue, 19 Sep 2006 18:08:28 +0200, "tony" <tda_silva@nospam.hotmail.com> wrote:
>Hi,
>
>I dont know what I am doing wrong - but when I substr a variable then my
>mysql returns no results.
>
>eg (msisdn is +445621458 for example:)
>$searchnum = substr($msisdn, 3);
>mysql_connect("localhost",$MysqlName,$MysqlPW);
>$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
>datesent >= '$yesterdaysdate' AND number LIKE '%$searchnum'";
>$Results = MySQL($dbName,$Selectstr);
>$RowCount = mysql_num_rows($Results);
>
>...Rowcount returns a 0 value,
>
>If I do this, I get results:
>
>$Selectstr = "SELECT * FROM sentmessages WHERE datesent <='$nowdate' AND
>datesent >= '$yesterdaysdate' AND number LIKE '%5621458'";
>
>What am I doing wrong?
>
if type this...
<?
$msisdn = "+445621458";
$searchnum = substr($msisdn, 3);
echo $searchnum ; // returns 5621458
echo "<br>";
echo strlen($msisdn); // returns 10
?>
so if you are getting a stringlength of 18 then $msisdn is not returning what you expect it
to maybe you add $msisdn = trim($msisdn); might be white space around the var you can't see
|
|
|
|
|