Jump to content

[SOLVED] query appending using an array


rbragg

Recommended Posts

I have built a search script that searches based on what a user has entered. In this case, the user has entered a value into a textfield that is brought in with the GET method. I use that value to find the S_NUM to those matching values.

 

Using this while loop echoes each S_NUM for each match, however, when I run the appended query, the query only uses the LAST matching S_NUM and I get one record. For example, there may be 3 S_NUM's that match the query (56, 58, 59) and the appending query only displays one record (59) when I need 3:

 

<?php 
# start of $querySearch here and I'm appending to it based on some criteria
# criteria:
if ( !empty($_GET['searchStudent']) )
{
  $gotStudent = $_GET['searchStudent'];

  $queryStudentResult = "
  SELECT s_num
  FROM student
  WHERE student.s_first LIKE '%" . $gotStudent . "%' OR student.s_last LIKE '%" . $gotStudent . "%'
  ";
  $studentResult= ociparse($connect, $queryStudentResult);
  ociexecute($studentResult);

  while ( ocifetch($studentResult) )
  {
    $studentNum = ociresult($studentResult,"S_NUM");
    echo "<br>studentNum: " . $studentNum . "<br>";
  }
  
  $querySearch.= "AND call.s_num = " . $studentNum . " ";
}?>

 

I also realize I need to make some upper/lower changes with using LIKE, but first I'm just trying to get this appending functioning. How to I manipulate an array to get my desired results here? I have also tried using foreach within the While loop.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.