Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Instructions
- ------------
- - Go through this function line by line, and explain what the code does on each line
- - Are there any mistakes that need correcting?
- - What does the function do overall?
- - What use case do you think this function serves? What's the business logic behind needing this function?
- - Given your understanding of the function, what potential outputs do you expect from calling: one("table_name", "column_name, "John")
- <?php
- function check_name($table, $column, $source_value, $counter = "", $arr_where = array(), $file_extension)
- {
- if($counter == "")
- {
- $attempted_new_name = $source_value.$file_extension;
- }
- else
- {
- $attempted_new_name = $source_value."-".$counter.$extension;
- }
- $where = "";
- if(count($arr_where) > 0)
- {
- $where = " AND ".implode(" AND ",$arr_where);
- }
- $sql = "SELECT ".$column." FROM ".$table." WHERE ".$column." = ".sql_safe($attempted_new_name).$where;
- $result = mysqli_query_error_logged($sql);
- if(mysqli_num_rows($result) == 0)
- {
- return $attempted_new_name;
- }
- else
- {
- if($counter = "")
- {
- $counter = 2;
- }
- else
- {
- $counter++;
- }
- return one($table, $column, $source_value, $counter, $arr_where, $file_extension);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement