Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7545891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:03:10+00:00 2026-05-30T09:03:10+00:00

Hello I’m using flexigrid and i have a problem, i don’t know why it

  • 0

Hello I’m using flexigrid and i have a problem, i don’t know why it keeps on saying
Invalid argument supplied for foreach() and Undefined variable: rows I looked at the code it seems right to me , idont know i may have overlooked but can you help me, Thanks

Heres My code.

<?php
$page = isset($_POST['page']) ? $_POST['page'] : 1;
$rp = isset($_POST['rp']) ? $_POST['rp'] : 10;
$sortname = isset($_POST['sortname']) ? $_POST['sortname'] : 'name';
$sortorder = isset($_POST['sortorder']) ? $_POST['sortorder'] : 'desc';
$query = isset($_POST['query']) ? $_POST['query'] : false;
$qtype = isset($_POST['qtype']) ? $_POST['qtype'] : false;


$usingSQL = true;
function runSQL($rsql) {

    $db['default']['hostname'] = "localhost";
    $db['default']['username'] = 'root';
    $db['default']['password'] = "";
    $db['default']['database'] = "testdb";

    $db['live']['hostname'] = 'localhost';
    $db['live']['username'] = 'root';
    $db['live']['password'] = '';
    $db['live']['database'] = 'testdb';

    $active_group = 'default';

    $base_url = "http://".$_SERVER['HTTP_HOST'];
    $base_url .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

    $connect = mysql_connect($db[$active_group]['hostname'],$db[$active_group]['username'],$db[$active_group]['password']) or die ("Error: could not connect to database");
    $db = mysql_select_db($db[$active_group]['database']);

    $result = mysql_query($rsql) or die ($rsql);
    return $result;
    mysql_close($connect);
}

function countRec($fname,$tname) {
        $sql = "SELECT count($fname) FROM $tname ";
    $result = runSQL($sql);
    while ($row = mysql_fetch_array($result)) {
            return $row[0];
    }
}

$sort = "ORDER BY $sortname $sortorder";
$start = (($page-1) * $rp);

$limit = "LIMIT $start, $rp";

$where = "";
if ($query) $where = " WHERE $qtype LIKE '%".mysql_real_escape_string($query)."%' ";

$sql = "SELECT * FROM city $where $sort $limit";
$result = runSQL($sql);

$total = countRec("ID","city $where");

if(!isset($usingSQL)){
    include dirname(__FILE__).'/countryArray.inc.php';
    if($qtype && $query){
            $query = strtolower(trim($query));
            foreach($rows AS $key => $row){
                    if(strpos(strtolower($row[$qtype]),$query) === false){
                            unset($rows[$key]);
                    }
            }
    }
    //Make PHP handle the sorting
    $sortArray = array();
    foreach($rows AS $key => $row){
            $sortArray[$key] = $row[$sortname];
    }
    $sortMethod = SORT_ASC;
    if($sortorder == 'desc'){
            $sortMethod = SORT_DESC;
    }
    array_multisort($sortArray, $sortMethod, $rows);
    $total = count($rows);
    $rows = array_slice($rows,($page-1)*$rp,$rp);
}
header("Content-type: application/json");
$jsonData = array('page'=>$page,'total'=>$total,'rows'=>array());
foreach($rows AS $row){ **//THIS IS MY LINE 82**
    //If cell's elements have named keys, they must match column names
    //Only cell's with named keys and matching columns are order independent.
    $entry = array('id'=>$row['iso'],
            'cell'=>array(
                    'ID'=>$row['ID'],
                    'Name'=>$row['Name'],
                    'CountryCode'=>$row['CountryCode'],
                    'District'=>$row['District'],
                    'Population'=>$row['Population']

            ),
     );
     $jsonData['rows'][] = $entry;
 }
 echo json_encode($jsonData);

Thanks in advance .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:03:12+00:00Added an answer on May 30, 2026 at 9:03 am

    Your $rows is never defined or initialised before the below snippet (most likely its first use). In such an event it is disproportionately unlikely that the foreach will forecast the variable to loop upon.

    $query = strtolower(trim($query));
            foreach($rows AS $key => $row){
                    if(strpos(strtolower($row[$qtype]),$query) === false){
                            unset($rows[$key]);
                    }
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello I have strange problem. I configured spring + hibernate. I`m using annotation configuration
Hello I have this problem with PyQt4-dev-tools that include: * a user interface compiler
Hello I am new to the Objective C and I have a problem. I
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello we have an SQL server application running over a low bandwith connection. We
Hello , I am using arshaw fullcalendar v1.5.2 (only month view ) for property
Hello i have a TextField on my scene. It haves only digits, user input
Hello StackOverflow, I'd like to know if there is way to trigger an event
Hello guys i have an website online wich access the database. The database access
Hello I am using jQuery UI Accodions By default, the first accordion is shown

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.