Jump to content

[SOLVED] search db table for word and display that entire row


Recommended Posts

I have a db table in which it has 57 columns of different values, ($id, $q0 - $q56)

 

I want to add a search to find a word/value within the table, add if that specific row has that value in it, display that row or rows. Each row has their own id.

 

How would I go about doing this?

 

I know I would have a while loop to go thru columns id and q0 thru q56 to check each field for that word, once that word is found, output that row, using the id of the that row, then continue searching thru to find other rows that have that same word/valule.

i got it to work to find a specified value in a specific column, but i want it search all 56 columns.

 

below is what i had envisioned

 

$query="SELECT * FROM forms_dieattachedsolder WHERE (q0 = '1' OR q1 = '1' OR q2 = '1' OR q3 = '1' OR q4 = '1' OR q5 = '1' OR q6 = '1' OR q7, q8 = '1' OR q9 = '1' OR q10 = '1' OR q11 = '1' OR q12 = '1' OR q13 = '1' OR q14 = '1' OR q15 = '1' OR q16 = '1' OR q17 = '1' OR q18 = '1' OR q19 = '1' OR q20 = '1' OR q21 = '1' OR q22 = '1' OR q23 = '1' OR q24 = '1' OR q25 = '1' OR q26, q27 = '1' OR q28 = '1' OR q29 = '1' OR q30 = '1' OR q31 = '1' OR q32 = '1' OR q33 = '1' OR q34 = '1' OR q35 = '1' OR q36 = '1' OR q37 = '1' OR q38 = '1' OR q39 = '1' OR q40 = '1' OR q41 = '1' OR q42 = '1' OR q43 = '1' OR q44 = '1' OR q45, q46 = '1' OR q47 = '1' OR q48 = '1' OR q49 = '1' OR q50 = '1' OR q51 = '1' OR q52 = '1' OR q53 = '1' OR q54 = '1' OR q55 = '1' OR q56 = '1')";

$result=mysql_query($query);

 

while ($row = mysql_fetch_array($result))

{

$i = 0;

$t = 1;

echo '<tr>';

 

while($i <= 56)

{

echo '<td name="'.$t.'">';

echo $row['q'.$i];

echo '</td>';

$i++;

$t++;

}

 

echo '</tr>';

}

 

-----------------------------

 

this is what i had where it would spit out the entire record if you found that value within that record

 

$query="SELECT * FROM forms_dieattachedsolder WHERE q0 = '1'";

err...found some misprints in there

 

this should do it

 

$query="SELECT * FROM forms_dieattachedsolder WHERE (q0 = $token OR q1 = $token OR q2 = $token OR q3 = $token OR q4 = $token OR q5 = $token OR q6 = $token OR q7 = $token OR q8 = $token OR q9 = $token OR q10 = $token OR q11 = $token OR q12 = $token OR q13 = $token OR q14 = $token OR q15 = $token OR q16 = $token OR q17 = $token OR q18 = $token OR q19 = $token OR q20 = $token OR q21 = $token OR q22 = $token OR q23 = $token OR q24 = $token OR q25 = $token OR q26 OR q27 = $token OR q28 = $token OR q29 = $token OR q30 = $token OR q31 = $token OR q32 = $token OR q33 = $token OR q34 = $token OR q35 = $token OR q36 = $token OR q37 = $token OR q38 = $token OR q39 = $token OR q40 = $token OR q41 = $token OR q42 = $token OR q43 = $token OR q44 = $token OR q45 OR q46 = $token OR q47 = $token OR q48 = $token OR q49 = $token OR q50 = $token OR q51 = $token OR q52 = $token OR q53 = $token OR q54 = $token OR q55 = $token OR q56 = $token)";

 

 

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.