Results 1 to 9 of 9

Thread: make a query with the value of text

  1. #1
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default make a query with the value of text

    hi!

    I have problems to give the value of a text.

    I have in a PHP this:

    Code:
    <?php
    $searchq  = strip_tags($_GET['q']);
    $getRecord_sql = 'select pkey from jiraissue where project = 10040 and pkey like "%'.$searchq.'%"';
    $getRecord = mysql_query($getRecord_sql);
    if(strlen($searchq)>0){
    echo '<ul>';
    while ($row = mysql_fetch_array($getRecord)) {
    ?>
        <li><a href="lib/consultas.php?accion=E" onclick="load('lib/consultas.php?accion=E','consulta');return false;">
    and in my file consultas.php, the case E:

    Code:
    case 'E':		
    $queEmp	= "select pkey, created, UPDATED, reporter, assignee, summary, description from `jiraissue` where project = 10040 and pkey like ".$search-q2." ";  
    $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
    $totEmp = mysql_num_rows($resEmp);
    if ($totEmp> 0) {
    	while ($rowEmp = mysql_fetch_assoc($resEmp)) {
    		echo "<strong>Incidencia:</strong> <u>".$rowEmp['pkey']."</u><br>";
    		echo "<strong>Data:</strong> ".$rowEmp['created']." / ".$rowEmp['UPDATED']."<br>";		
    		echo "<strong>Tecnic Obre:</strong> ".$rowEmp['reporter']."<br>";
    		echo "<strong>Tecnic Actual:</strong> ".$rowEmp['assignee']."<br>";
    		echo "<strong>Descripcio incidencia:</strong> ".$rowEmp['summary']."<br>";
    		echo "<strong>Intervencions:</strong> ".$rowEmp['description']."<br><br>";
    		}
    	}
    break;	
    mysql_close($conexion);

    Why the result of my query is:

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0' at line 1

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Thats a very, very sloppy query. Change it to this:
    Code:
    $getRecord_sql = 'SELECT `pkey` FROM `jiraissue` WHERE project = "10040" and `pkey` LIKE "%'.$searchq.'%"';
    For your second one just capitalize all of the commands such as SELECT, FROM, LIKE, WHERE, IN, AND more (haha), `tick` all of the table names or fields, and put double quotes after equal signs(like the highlighted above)
    Jeremy | jfein.net

  3. #3
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh sorry!
    The problem is the query of "CASE: E". It's return the error.

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Quote Originally Posted by Nile View Post
    For your second one just capitalize all of the commands such as SELECT, FROM, LIKE, WHERE, IN, AND more (haha), `tick` all of the table names or fields, and put double quotes after equal signs(like the highlighted above)
    Read my whole post.
    Jeremy | jfein.net

  5. #5
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I change it.

    next the case E I insert:

    case 'E':
    echo "hello value!: <br>";
    echo ?????

    in ???? what's the value of my selected AutoSuggest content into the text box?

  6. #6
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    May I please see your changed code?
    Jeremy | jfein.net

  7. #7
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    this is the text box into a index.php:

    Code:
    <input name="search-q2" id="search-q2" type="text" onkeyup="javascript:autosuggest2()"/>
    and into the consultas.php, the case E:

    Code:
    case 'E':		
    	
    $queEmp	= "select `pkey`, `created`, `UPDATED`, `reporter`, `assignee`, `summary`, `description` from `jiraissue` where project = 10040 and `pkey` like ???VARIABLE????   ";		
    $resEmp = mysql_query($queEmp, $conexion) or die(mysql_error());
    $totEmp = mysql_num_rows($resEmp);
    if ($totEmp> 0) {	
    	while ($rowEmp = mysql_fetch_assoc($resEmp)) {
    		echo "<strong>Incidencia:</strong> <u>".$rowEmp['pkey']."</u><br>";
    		echo "<strong>Data:</strong> ".$rowEmp['created']." / ".$rowEmp['UPDATED']."<br>";		
    		echo "<strong>Tecnic Obre:</strong> ".$rowEmp['reporter']."<br>";
    		echo "<strong>Tecnic Actual:</strong> ".$rowEmp['assignee']."<br>";
    		echo "<strong>Descripcio incidencia:</strong> ".$rowEmp['summary']."<br>";
    		echo "<strong>Intervencions:</strong> ".$rowEmp['description']."<br><br>";
    	}
    }
    break;	
    mysql_close($conexion);
    and I have a Framework:

    Code:
    function autosuggest1() {
    q = document.getElementById('search-q2').value;
    // Set te random number to add to URL request
    nocache = Math.random();
    http.open('get', 'lib/search_incidencias.php?q='+q+'&nocache = '+nocache);
    http.onreadystatechange = autosuggestReply;
    http.send(null);
    }
    
    function autosuggestReply() {
    if(http.readyState == 4){
    	var response = http.responseText;
    	e = document.getElementById('results');
    	if(response!=""){
    		e.innerHTML=response;
    		e.style.display="block";
    	} else {
    		e.style.display="none";
    	}
    }
    }
    and, search_incidencias.php:

    Code:
    <?php
    $searchq		=	strip_tags($_GET['q']);
    $getRecord_sql = 'SELECT `pkey` FROM `jiraissue` WHERE project = "10040" and `pkey` LIKE "%'.$searchq.'%"';
    $getRecord		=	mysql_query($getRecord_sql);
    if(strlen($searchq)>0){
    echo '<ul>';
    while ($row = mysql_fetch_array($getRecord)) {
    ?>
    	<li><a href="lib/consultas.php?accion=E" onclick="load('lib/consultas.php?accion=E','consulta');return false;">
    <?php 
    echo $row['pkey']; 
    ?>

    here is all my code...

  8. #8
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    If I put echo $search-q2; the result is 0.
    And, If I put echo $queEmp; i see a white page without results.

    With PHP is possible to give a variable of another PHP file?

  9. #9
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oh! I change $search-q2 for search_q2 because
    "-" is not a valid character.
    And, when I put echo $search_q2;. The result of echo is a white page without results.
    Last edited by guif; 08-13-2008 at 12:24 PM.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •