Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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><td><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>";
share|improve this question
 
Do you use PDO or mysqli ? Could we get an example of your php code? –  Machiel Oct 17 '10 at 21:57
 
What's your PHP Code? –  Duniyadnd Oct 17 '10 at 21:59
 
Most likely, the data is not what you expect it to be, as with the queries there is nothing wrong. Be very aware about non-displayed / easy to miss characters, like starting spaces, html-tags not showing up in a browsers, etc., etc. –  Wrikken Oct 17 '10 at 22:08
 
Have you tried storing the php query in a string, then echoing the string and pasting it into mysql? –  Sam Dufel Oct 17 '10 at 22:08
add comment

3 Answers

up vote 2 down vote accepted

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.

share|improve this answer
 
what's the difference between the two versions of the second problem? –  sebastian Oct 18 '10 at 14:10
 
The variable you're assigning to. Pay attention. In the first case you have $int (not used), in the second you have $local (what you use in the while loop). –  Alin Purcaru Oct 18 '10 at 14:31
add comment

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
}

share|improve this answer
 
i didn't add that part, because i thought it's irrelevant –  sebastian Oct 17 '10 at 22:25
 
@sebastian - you may want to include that as it's the piece that's not working. Did you try print_r() the array and see if everything is there? –  Duniyadnd Oct 17 '10 at 22:36
add comment

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

share|improve this answer
 
i posted the wrong code. sorry. i was in a rush. –  sebastian Oct 18 '10 at 12:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.