April 3, 201313 yr Hey there, I need to be able to search all of the fields across a few of my tables i have created. I managed to get that far at least but im unsure on how to go about echoing out the data for links that go direct to that search item. if(preg_match("/^[a-zA-Z]+/", $_POST['search'])){ $name= mysql_real_escape_string($_POST['search']); $select = mysql_real_escape_string($_POST['where']); $moi = $_SESSION['id']; if ($select == 1):{ $src = '_clients'; } elseif ($select == 2):{ $src = '_invoices'; } elseif ($select == 3):{ $src = '_users'; } elseif ($select == 4):{ $src = '_product'; } elseif ($select == 5):{ $src = '_sales'; } elseif ($select == 6):{ $src = '_projects'; } endif; //connect to the database $res = mysql_query("SHOW COLUMNS FROM $src"); if (mysql_num_rows($res) > 0){ $i=0; while($rows = mysql_fetch_array($res)){ if ($i == 0){ $q = "SELECT * FROM $src WHERE ".$rows[0]." LIKE '%".$name."%'"; echo $rows[0]; } else { $q.=" or ".$rows[0]." LIKE '%".$name."%'"; } $i++; } $q .= "AND uid = $moi"; } $newstr = str_replace('_', '', $src); $sql = "SELECT * FROM $src WHERE name LIKE '%" . $name . "%'"; $result = mysql_query($q) or die(mysql_error()); echo 'We found <strong>'.mysql_num_rows($result).'</strong> Results to Display for the term <strong>'.$name.'</strong>.<br/><br/>'; while($row=mysql_fetch_assoc($result)){ //-display the result of the array echo '<a href="'.$newstr.'.php">found</a><br/><br/>'; } if (mysql_num_rows($result)==0){ echo 'Found <strong>0</strong> Results to Display for the Term <strong>'.$name.'</strong>.'; } } else{ echo "<p>Please enter a search query</p>"; } Hope fully this makes sense just by reading the above.
Create an account or sign in to comment