开发者

problem with MySQL queries in PHP

开发者 https://www.devze.com 2023-01-20 03:46 出处:网络
I have the following queries that work perfectly in MySql: SELECT * FROM rapoarte WHERE nrtel LIKE \'0256%\' OR nrtel LIKE \'0356%

I have the following queries that work perfectly in MySql:

  1. SELECT * FROM rapoarte WHERE nrtel LIKE '0256%' OR nrtel LIKE '0356%

  2. SELECT * FROM rapoarte WHERE nrtel NOT LIKE '07%' AND nrtel NOT LIKE '0256%' AND nrtel NOT LIKE '0356%'

  3. SELECT * FROM rapoarte WHERE nrtel LIKE '07%'

in PHP they will result the following:

  1. results just for LIKE '0256%'

  2. no results

  3. inclomplete results. i have phone numbers that start with 076, 075 and it only shows the numbers that start with 076.

Anyone know why?

thanks, Sebastian

EDIT

here is the code:

$select_int= mysql_query("SELECT * FROM rapoarte WHERE nrtel LIKE '0256%' OR nrtel LIKE '0356%'");
$local = mysql_fetch_array($select_int);
echo "<table align='center' border='0' width='600'><tr><td><b>Ziua</b></td><t开发者_开发百科d><b>Ora</b></td><td><b>Trunchi</b></td><td><b>interior</b></td><td><b>Durata</b></td><td><b>Numar Format</b></td></tr>";
while($int = mysql_fetch_array($select_int)) {
    echo "<tr>
    <td>".$local['ziua']."</td> 
    <td>".$local['ora']."</td>
    <td>".$local['linie']."</td>
    <td>".$local['interior']."</td>
    <td>".$local['durata2']."</td>
    <td>".$local['nrtel']."</td></tr>";
}
echo "</table>";


Again...

Here $local = mysql_fetch_array($select_int); you discard your first line. You fetch it and you don't use it.

The second problem is here $int = mysql_fetch_array($select_int). You actually want $local = mysql_fetch_array($select_int) because that's what you use in the while block.


You seem to be discarding the first result on the 2nd line with

$int = mysql_fetch_array($select_int);

...not to mention the query in the code snippet you edited in doesn't actually match any of the three you claim work correctly.

You're not iterating over the results, rather, you're just getting the first one.

while(($local = mysql_fetch_array($select_int)) != null){
    // $local contains 1 result row
}


The query you're using in your PHP script doesn't use "LIKE"

0

精彩评论

暂无评论...
验证码 换一张
取 消