1

I got a little problem here with my SQL query...

I debugged where the problem resides and realized that the varchar/text column seemed to stop my php function.

Here is my code:

$queryTest = mysqli_query($link, "SELECT dos_nom,dos_id FROM dossier");

while($dataTest = mysqli_fetch_assoc($queryTest)) {

if($dataTest['dos_id'] == $myparameter) {
    $toreturn.= '<option class="text-'.$dataTest['dos_id'].'" value="'.$dataTest['dos_nom'].'" selected>'.$dataTest['dos_nom'].'</option>';
            }
        }

The problem is in the value $dataTest['dos_nom']. Without which my query works (it prints the page normally), but I don't know why. With it, it doesn't work (it prints the top of the page, and nothing from/after my php function)...

To be precise, i use it in an ajax function.

Thanks in advance!

EDIT: I tried to print only 1 row from 'dos-nom', it works! But i when try to print out more than 1 row, the function stops!

My code:

$queryTest2 = mysqli_query($link, "SELECT * FROM dossier");
while($dataTest2 = mysqli_fetch_assoc($queryTest2)) 
        {                   
           $test[0] = $dataTest2['dos_nom'];
        }
if($dataTest['dos_id'] == $dos_id) 
  {
    $toreturn.= '<option class="text-'.$dataTest['dos_id'].'" >'.$test[0].'</option>';
  }

It prints only the last line this way. If i put a WHERE in the query it will stop the function, so i don't know what to do!

ANSWER:

É / À were in my database, i replaced them by E and A, problem solved!

5
  • 4
    There is a </span> before the closing of the option that seems strange to me...
    – Masiorama
    Mar 24, 2015 at 15:55
  • 1
    What does var_dump($dataTest); placed after your while do? Mar 24, 2015 at 16:03
  • Pay attention on special charactrers in strings, e.g. use htmlentities
    – lp_
    Mar 24, 2015 at 16:04
  • Make sure to check your PHP error logs too.
    – Mike
    Mar 24, 2015 at 16:46
  • I forgot to delete the </span>, thanks :) (but it still doesn't work) var_dump($dataTest); stop my php function too.... No error logs... This php function has for goal to put this select into another php file which contains all HTML and JS. i'm calling this function with an ajax function, so if the function fail i got nothing in return... Or i don't know how to print it.
    – Fakebounce
    Mar 25, 2015 at 10:22

2 Answers 2

0

try to use addslashes() function like

 addslashes($dataTest['dos_nom'])

maybe the value contains some backslash or some junk characters which may be breaking your code

1
  • It did not solve the problem, but i had some junk characters in my database, when i removed them it worked! Thanks :)
    – Fakebounce
    Apr 10, 2015 at 13:17
0

I see nothing wrong with your code, except the logic - you only output when option is selected.

So as you said (it prints nothing)

Let's try print something:

$queryTest = mysqli_query($link, "SELECT dos_nom,dos_id FROM dossier");

while($dataTest = mysqli_fetch_assoc($queryTest)) {

    $selected = ($dataTest['dos_id'] == $myparameter)?' selected ':' ';
    $toreturn.= '<option class="text-'.$dataTest['dos_id'].'" value="'.$dataTest['dos_nom'].'" '.$selected.'>'.$dataTest['dos_nom'].'</option>';

}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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