mysql - Search function in PHP works with numeric values but doesn't work with letters/words -


people can order links @ platform , these stored in 2 different tables, eg wp_project , wp_articles. reason when people place order 1 link 1 project row gets created , 1 article row gets created.

however if client orders 10 links there 1 project entry , ten article entries. isn't relevant problem explain how system works.

there 2 common identifiers projects , articles, both id , project title stored in both inpu_project , inpu_articles.

now if want echo links 1 project built search function can select project id, click search , whether client ordered 1 link or 20 links amount of links show.

the problem starts when want search based on project title instead of id, non-numeric words (with spaces in between sometimes).

this prevent error undefined index in error logs

    $where_clouse=''; 

this search function based on project title:

    if(isset($_get['todo']) && $_get['todo']=='search')     {         if($_get['proid']!=0){             $where_clouse.=' , p.`project_title`='.$_get['proid'];         }     } 

this database query pull links it:

    $sql="select p.`project_title`, p.`backlink` `inpu_articles` p  p.`post_it_posted` = '1' ".$where_clouse."  order p.`project_title`  asc";     $backlinks=$wpdb->get_results($sql, array_a); 

this actual search function triggers first code pasted:

    <p>select project title , hit search!</p>     <form action="" method="get">         <input type="hidden" name="todo" id="todo" value="search" />         <select name="proid" id="proid">         <option value="0">all projects</option>         <?php $projects=gettitles(); foreach($projects $project){ ?>             <option value="<?php echo $project['title']; ?>" <?php if(isset($_get['proid']) && $_get['proid']==$project['title'] ) { echo 'selected="selected"';  } ?> ><?php echo $project['title'] ?>             </option>         <?php } ?>         </select>         <input class="submit_search" type="submit" id="search_button" value="search"/>     </form> 

and code pulls project titles project table:

    function gettitles($where=false)     {         global $wpdb;         $sql="select  `title`, `link` `inpu_project` `link`='1' order `title` asc";         $result = $wpdb->get_results($sql, array_a);         return $result;     } 

all pretty straight forward , works 100% fine if replace non-numeric title in code both inpu_articles , inpu_project tables numeric id.

then code does, when use project title instead shows of links every client ever ordered , no error shows in database. it's can't find match or something, plain weird.

so missing here? not possible match words or there should adjust when using words instead of numeric values?

lastly, it's worth, code echos query:

    <?php foreach ($backlinks $backlink) {         $backlink_overview=$backlink['backlink'];     ?>         <ul>             <li><?php echo $backlink_overview; ?></li>         </ul>     <?php } ?> 

the titles show in form / search drop down menu surprised can't match project title title that's stored in article table.

my gut says goes wrong:

    p.`project_title`='.$_get['proid']; 

but doesn't throw syntax errors or errors whatsoever, shows links stored in inpu_article table, ignorning search function altogether.

the problem in condition where_clause , where_clause itself. check input need check if parameter set , not empty. clause need put string quotes. change part of code bellow

if(isset($_get['proid']) && !empty($_get['proid'])){        $where_clouse.=" , p.project_title='".$_get['proid']."'";    } 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -