• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

eregi

cheatpark

­
NLC
In php I am using the eregi function for a search script to see if the input matches with a database row. The problem is I can only get one result to be displayed. I think its because I am using mysql_fetch_object() but then thats the only one that will get results that will work in eregi. If I try mysql_fetch_array() in eregi then I get an error. Is there a thing I can do with backslashes or something to get the mysql_fetch_array() working in eregi? Just to it easier here's what I do with mysql_fetch_object()
PHP:
eregi($searchtext, $row->Name);
And here is what I try to do with mysql_fetch_array but it won't work:
PHP:
eregi($searchtext, $row[Name]);
 
When I use in_array() I get this error:

Warning: Wrong datatype for second argument in call to in_array in c:\www\public_html\search2.php on line 24

The code I use is:

PHP:
if(in_array($searchtext, $row[Name]) !== $searchtext) {
 
Its cuz in_array must only check the array, not a key in the array (in your array, its "name")
make your SQL query like this :
PHP:
SELECT name FROM bla
and then change your code to :
PHP:
if(in_array($searchtext, $row) )
 
I still can't get it to work. With eregi I can get it to work but it displays one result. Here's my source:

PHP:
<?
include("config.php");
include("common.php");
if($mode == "enter") {
?>
<form action=search2.php>
<input type=hidden name=mode value=results>
<table width=100%>
<tr><td><input type=text name=searchtext></td></tr>
<tr><td><input type=submit value=Search></td></tr>
</form>
<?
}
$result = mysql_query("SELECT * FROM arenatopics");
while($row = mysql_fetch_array($result))
if($mode == "results" && eregi($searchtext, $row[Name])) {
?>
<table width=100%>
<tr><td>Page name: <a href=view.php?ID=<? echo $row[ID]; ?>><font><? echo $row[Name]; ?></font></a></td></tr>
</table>
<?
exit;
}
?>
 
Try to do it with in_arra like I told you, i will work...
(unless you actualy using REGEX, eregi() will be waste of time cuz its very slow and you can do same stuff without REGEX and faster)
 
Back
Top