Hello, there was a big problem, but I do not want to waste your time and describe the problem only at this stage:

There is one function and in it the var_dump result of the SQL conversion => Array. The fact is that I need only a specific entry in the database, but it does not work to get it. Tried with while - the result is also nothing, just displays nothing purely. Also tried var_dump with while but without specifying a specific cell.

Here is the current function code (with while):

function Redirect($user_id,$sql_connection){ $sql_query = "SELECT * FROM `links` WHERE `owner_id` = ".$user_id." "; $sql_response = mysql_query($sql_query); while ($row = mysql_fetch_assoc($sql_response)){ var_dump($row); } } 

I tried this without while:

 function Redirect($user_id,$sql_connection){ $sql_query = "SELECT * FROM `links` WHERE `owner_id` = ".$user_id." "; $sql_response = mysql_query($sql_query); $row = mysql_fetch_assoc($sql_response); // в этом коде убран только while! var_dump($row); } 

Here is a working version, but it displays all the records, but I need only one:

 function Redirect($user_id,$sql_connection){ $sql_query = "SELECT * FROM `links`"; // убран поиск записи по WHERE $sql_response = mysql_query($sql_query); while ($row = mysql_fetch_assoc($sql_response)){ var_dump($row); } } 

I think the problem is in the little things, but now it doesn’t work out at all, but the problem is big.

  • In the second variant, try to handle the error in mysql_query (). Everything looks fine, the option should work - maybe some kind of error from MySQL. - cheops

1 answer 1

 $sql_query = "SELECT * FROM `links` WHERE `owner_id` = ".$user_id." "; 

This request may not return anything (if there are no problems with the connection) for three reasons.

  1. The substituted $user_id not in the table. Check if he is there.
  2. The owner_id field is not numeric. In this case, you need to correct the query in this way (apostrophes around ".$user_id." ):

     $sql_query = "SELECT * FROM `links` WHERE `owner_id` = '".$user_id."' "; 
  3. In $user_id there is some unknown heresy that the DB is not capable of recognizing.

Write the second line in the var_dump($sql_query) function var_dump($sql_query) , copy the output and execute the query directly into the database, for example phpmyadmin .

Some tips:

  1. Use mysqli instead of mysql . The mysql extension is deprecated and is no longer supported.
  2. You can see how many rows are in the sample by using the mysql_num_rows function.
  3. After completing the request, monitor the errors. mysql_error