kasper1339
11-21-2010, 12:50 PM
On my page I've got a search feature, where the user can search through the database. In mysql i've got different tables with the contents I want the search to go through. So I need to search through 2 queries. This is how I've done it.
<?
$records_per_page = 10;
//-query the database table
$sql1="select * from fagudtryk_muskler where dansk like \"$trimmed%\" order by dansk";
$sql2="select * from fagudtryk_led where dansk like \"$trimmed%\" order by dansk";
$result = array("$sql1", "$sql2");
foreach($result as $value)
//-run the query against the mysql query function
$numro=mysql_query($value);
//-count results
$numrows=mysql_num_rows($numro);
$num_pages = ceil($numrows/$records_per_page);
//Determine the page to display
$current_page = (isset($_GET['pg']))?$_GET['pg']:1;
if($current_page<1 || $current_page>$num_pages) { $current_page = 1; }
//Define the limit start position for the current page of records (for current filter)
$limitstart = (($current_page-1)*$records_per_page);
// Build SQL Query
$query = "select * from fagudtryk_muskler where dansk like \"$trimmed%\" order by dansk LIMIT $limitstart, $records_per_page "; // EDIT HERE and specify your table and field names for the SQL query
$query1 = "select * from fagudtryk_led where dansk like \"$trimmed%\" order by dansk LIMIT $limitstart, $records_per_page "; // EDIT HERE and specify your table and field names for the SQL query
$numresults = array("$query", "$query1");
foreach($numresults as $value1)
$value2=mysql_query($value1);
// If we have no results, offer a google search as an alternative
if ($numrows == 0)
{
echo "<p>Din søgning: "" . $trimmed . "" retunerede ingen resultater</p>";
}
// get results
if ($numrows > 0)
{
// display what the person searched for
echo "<p>Resultat for: "" . $var . "" </p>";
// now you can display the results returned
while($row=mysql_fetch_array($value2)){
$dansk =$row['dansk'];
$ID =$row['id'];
//-display the result of the array
echo "<li>" . "<a href='javascript:void()' onclick='window.location.href=\"search.php?id=" . ($ID) . "&dansk=". ($dansk) . "\"; parent.scrollTo(0,0); return false'><p> " .$dansk . " </a></li>\n</p>";
}}
The problem is that it only uses the last query, so I don't get any results from the first query. What is wrong?
<?
$records_per_page = 10;
//-query the database table
$sql1="select * from fagudtryk_muskler where dansk like \"$trimmed%\" order by dansk";
$sql2="select * from fagudtryk_led where dansk like \"$trimmed%\" order by dansk";
$result = array("$sql1", "$sql2");
foreach($result as $value)
//-run the query against the mysql query function
$numro=mysql_query($value);
//-count results
$numrows=mysql_num_rows($numro);
$num_pages = ceil($numrows/$records_per_page);
//Determine the page to display
$current_page = (isset($_GET['pg']))?$_GET['pg']:1;
if($current_page<1 || $current_page>$num_pages) { $current_page = 1; }
//Define the limit start position for the current page of records (for current filter)
$limitstart = (($current_page-1)*$records_per_page);
// Build SQL Query
$query = "select * from fagudtryk_muskler where dansk like \"$trimmed%\" order by dansk LIMIT $limitstart, $records_per_page "; // EDIT HERE and specify your table and field names for the SQL query
$query1 = "select * from fagudtryk_led where dansk like \"$trimmed%\" order by dansk LIMIT $limitstart, $records_per_page "; // EDIT HERE and specify your table and field names for the SQL query
$numresults = array("$query", "$query1");
foreach($numresults as $value1)
$value2=mysql_query($value1);
// If we have no results, offer a google search as an alternative
if ($numrows == 0)
{
echo "<p>Din søgning: "" . $trimmed . "" retunerede ingen resultater</p>";
}
// get results
if ($numrows > 0)
{
// display what the person searched for
echo "<p>Resultat for: "" . $var . "" </p>";
// now you can display the results returned
while($row=mysql_fetch_array($value2)){
$dansk =$row['dansk'];
$ID =$row['id'];
//-display the result of the array
echo "<li>" . "<a href='javascript:void()' onclick='window.location.href=\"search.php?id=" . ($ID) . "&dansk=". ($dansk) . "\"; parent.scrollTo(0,0); return false'><p> " .$dansk . " </a></li>\n</p>";
}}
The problem is that it only uses the last query, so I don't get any results from the first query. What is wrong?