Note that there are some explanatory texts on larger screens.

plurals
  1. PODoing a second search automatically
    primarykey
    data
    text
    <p>I have PHP code to do a simple MySQL database search with only two columns of data. I suspect I am probably already going the long way around when I could simply do it a different way.</p> <p>I have a form that you can put in a name or an IP address and it will search for either of them in the database, and output the results. Each name can only have one IP address (the last one they used) (full unique names will only have 1 result, or multiple results if partial names match multiple accounts), but an IP address can have multiple names (people who use multiple accounts on the same IP). What I want to do is have it so if you search for a name, it will do the regular single result (if the full unique name was typed), but then under it, do a secondary search for the IP if only the NAME was searched for in the form.</p> <blockquote> <p>"You search for NAME has returned these results: {results}. We also found these accounts who have used the same IP address: {results matching the same IP from the first result of the Name search}".</p> </blockquote> <p>Here is the code I have so far:</p> <hr> <p><em>(Some cleanup since I am using GET)</em></p> <pre><code>$iplookup = strtolower($_GET['iplookup']); $iplookup = stripslashes($iplookup); $iplookup = strip_tags($iplookup); $iplookup = preg_replace('/[^A-Za-z0-9\._]/','',$iplookup); $sql = mysql_query("select * from banlistip where name like '%$iplookup%' OR lastip like '%$iplookup%' "); if (empty($iplookup)) { echo '&lt;br&gt;&lt;b&gt;You left the search form empty.&lt;/b&gt;'; } else { while ($row = mysql_fetch_array($sql)) { echo '&lt;br/&gt; Name: '.$row['name']; echo '&lt;br/&gt; Player IP: '.$row['lastip']; echo '&lt;br/&gt;&lt;br/&gt;'; } </code></pre> <p>}</p> <hr> <p>And then right here it would get that <code>$row['lastip']</code> variable and then do a search for that, which would be the equivalent of just searching an ip address in the first place. </p> <hr> <p>The whole purpose of this is to eliminate a couple of steps and see all of the desired results at once. Usually, in order to do an IP search, I have to <strong>search the name, highlight + copy the ip, go back to the form, and then search the IP</strong>. </p> <hr> <hr> <p>The table with two columns named "name" and "lastip" respectively have data like this:</p> <pre><code>player1 111.111.111.111 player2 222.222.222.222 player3 111.000.111.000 player4 222.000.222.000 altaccount1 111.000.111.000 altaccount2 222.222.222.222 </code></pre> <p>(If you searched for Player2, you would get one result, since it is a unique name. If you searched for the IP of Player2, you would get two results [player2 + altaccount2], since there is an alternate account that uses the same IP address.) </p> <p>(Please excuse this very long post. I just want to provide as much details as I can, I have tried to research this, but having a block right now. <strong>Thanks so much, and again, sorry for making you read all of this.</strong>)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload