Help with Search Script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Help with Search Script

    Hi

    Im getting this error code on my index

    PHP Code:
    WarningInvalid argument supplied for foreach() in /home//public_html/12/html.tpl.php on line 3 
    this is the code in html.tpl.php
    PHP Code:
    <?php include 'head.inc.php'?>
             <div class="rmenu"><img src="a.gif" /> Search Results: [<?=$q?>]</div> 
          <?php foreach ($data['results'] as $result) :?>
             <div class="rmenu"><a href="<?php printf('tweak.php?u=%s&h=%d&w=%d'urlencode($result['url']), $result['height'], $result['width']); ?>"><img src="<?=$result['tbUrl'?>" alt="<?=$result['titleNoFormatting'?>" width="116" height="78"/></a><div class="text"><?=$result['titleNoFormatting'?></div></div>
          <?php endforeach ?>
          <div id="rmenu">
             <center><a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1))?>">Prev</a> | <a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1)) ?>">Next</a></center></div>
    this is what is included in valid.php which i think is causing error because when i put something in $s = array(''); like $s = array('SOMETHING HERE'); then the error goes away

    PHP Code:
    <?php
    $safe 
    = array("moderate""active");
    $image_type = array('''jpg''png''gif''bmp');
    $image_size = array('',);
    $s = array('SOMETHING HERE');
    shuffle($s);
    i tried messing with code but not getting anywhere
    Last edited by metulj; 18.03.13, 22:31.

    #2
    Originally posted by brentg View Post
    this is what is included in valid.php
    I'm not sure if valid.php is what you should be showing us, where is
    PHP Code:
    $data = array('values'); 
    ?
    Maybe you should be posting
    Code:
    head.inc.php
    instead
    libra.wen.ru

    Comment


      #3
      Your error is a simple one. The php function foreach is not getting a valid argument. Usually this is because the first argument passed to it isn't an array. You can debug by dumping the value of $data['results'] and seeing if its actually an array.

      A good dumping function I always use is this:

      Code:
      function dd($var)
      {
          ?><pre><?php print_r($var) ?></pre><?php
          die;
      }
      Then you can run $data right through the function dd($data) to see if there's an array with a key "result" and if that keys value is indeed an array itself.

      Comment


        #4
        Thanks so much all.

        @Creativekills might this be helpful?

        PHP Code:
        <?php include 'head.inc.php'?>
                 <div class="rmenu"><img src="a.gif" /> Search Results: [<?=$q?>]</div> 
              <?php foreach ($data['results'] as $result) :?>
                 <div class="rmenu"><a href="<?php printf('tweak.php?u=%s&h=%d&w=%d'urlencode($result['url']), $result['height'], $result['width']); ?>"><img src="<?=$result['tbUrl'?>" alt="<?=$result['titleNoFormatting'?>" width="116" height="78"/></a><div class="text"><?=$result['titleNoFormatting'?></div></div>
              <?php endforeach ?>
              <div id="rmenu">
                 <center><a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1))?>">Prev</a> | <a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1)) ?>">Next</a></center></div>
        <?php
        echo "<div class=\"rmenu\"><center>";
        echo 
        '<div class="header">';
        echo 
        '<font color="black">Copyright &copy; /font><br>';
        echo 
        '<a href="/disclaimer.php">Disclaimer</a><br/>';
        echo 
        "</div>";
        echo 
        "</body></html>";
        ?>

        Comment


          #5
          Can anyone assist with removing this error: Wallpapers - Choose Category & Search | PlayWap.Mobi

          All the codes are above

          Comment


            #6
            $data['results'] probably isn't an array, post from what you assigned that var.

            --------------

            The error is showing when the search is empty.

            PHP Code:
            <?php include 'head.inc.php'?> 
                     <div class="rmenu"><img src="a.gif" /> Search Results: [<?=$q?>]</div>  
                  <?php
            $results 
            = !empty($data['results']) ? $data['results'] : null;
            if (isset(
            $results)) {
             foreach (
            $results as $result) {?> 
                     <div class="rmenu"><a href="<?php printf('tweak.php?u=%s&h=%d&w=%d'urlencode($result['url']), $result['height'], $result['width']); ?>"><img src="<?=$result['tbUrl'?>" alt="<?=$result['titleNoFormatting'?>" width="116" height="78"/></a><div class="text"><?=$result['titleNoFormatting'?></div></div> 
                  <?php } }?> 
                  <div id="rmenu"> 
                     <center><a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1))?>">Prev</a> | <a href="<?php printf('?q=%s&safe=%s&size=%s&type=%s&p=%d'$GS -> search$GS -> safe$GS -> image_size$GS -> image_type, ($p 1)) ?>">Next</a></center></div>
            Last edited by arnage; 30.03.13, 00:34.
            <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

            Comment


              #7
              This the code in valid.php.

              PHP Code:
               <?php
              $safe 
              = array("moderate""active");
              $image_type = array('''jpg''png''gif''bmp');
              $image_size = array('',);
              $s = array('SOMETHING HERE');
              shuffle($s);
              when you insert a word in-place of "SOMETHING HERE" then the error goes away.

              Comment

              Working...
              X