MySQL table with similar column info - HELP!!!

Posted by George Garman on Stack Overflow See other posts from Stack Overflow or by George Garman
Published on 2010-06-05T15:44:45Z Indexed on 2010/06/05 15:52 UTC
Read the original article Hit count: 165

Filed under:
|

I have a DB with a table that is named "victim". The form that dumps the info into the table has room for two victims and therefore there is vic1_fname, vic1_lname, vic2_fname, vic2_lname, etc.. (business name, person first, person last, address, city, state, zip) a "1" and "2" of each. Now I want to search the DB and locate listed victims.

This is what I have so far:

$result = mysql_query(
                  "SELECT victim.*
                    FROM victim
                    WHERE vic1_business_name OR vic2_business_name  LIKE '%$search_vic_business_name%'
                    AND vic1_fname OR vic2_fname      LIKE '%$search_vic_fname%'
                    AND vic1_lname OR vic2_lname      LIKE '%$search_vic_lname%'
                    AND vic1_address OR vic2_address  LIKE '%$search_vic_address%'
                    AND vic1_city OR vic2_city        LIKE '%$search_vic_city%'
                    AND vic1_state OR vic2_state      LIKE '%$search_vic_state%'
                    AND vic1_dob OR vic2_dob          LIKE '%$search_vic_dob%'

                  ");

<table width="960" style="border: groove;" border=".5">
<tr><th colspan=10>You search results are listed below:</th></tr>
<tr>
<th>Case Number</th>
<th>Business Name</th>
<th>First Name</th>
<th>Last Name</th>
<th>DOB / Age</th>
<th>Address</th>
<th>City</th>
<th>State</th>
</tr>

<?php

while($row = mysql_fetch_array($result))
  { ?>

<tr>
<td align="center"><?php print $row['vic_business_name']; ?></td>
<td align="center"><?php print $row['vic_fname']; ?></td>
<td align="center"><?php print $row['vic_lname']; ?></td>
<td align="center"><?php print $row['vic_dob']; ?></td>
<td align="center"><?php print $row['vic_adress']; ?></td>
<td align="center"><?php print $row['vic_city']; ?></td>
<td align="center"><?php print $row['vic_state']; ?></td>
</tr>

<?php  }    ?>
</table>

The info did not display in the table until I changed the table to this:

<tr>
<td align="center"><?php print $row['vic1_business_name']; ?></td>
<td align="center"><?php print $row['vic1_fname']; ?></td>
<td align="center"><?php print $row['vic1_lname']; ?></td>
<td align="center"><?php print $row['vic1_dob']; ?></td>
<td align="center"><?php print $row['vic1_adress']; ?></td>
<td align="center"><?php print $row['vic1_city']; ?></td>
<td align="center"><?php print $row['vic1_state']; ?></td>
</tr>

<tr>
<td align="center"><?php print $row['vic2_business_name']; ?></td>
<td align="center"><?php print $row['vic2_fname']; ?></td>
<td align="center"><?php print $row['vic2_lname']; ?></td>
<td align="center"><?php print $row['vic2_dob']; ?></td>
<td align="center"><?php print $row['vic2_adress']; ?></td>
<td align="center"><?php print $row['vic2_city']; ?></td>
<td align="center"><?php print $row['vic2_state']; ?></td>
</tr>

Now it displays both rows, even if its empty. It doesn't matter if the victim was listed originally as vic1 or vic2, i just want to know if they are a victim.

I hope this makes sense. I can't get it to display the way I want, line-by-line, irregardless of whether you are vic1 or vic2.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql