PHP Issue :[ please help?

12 replies
Alright so I'm designing and coding a website and I have run into a small problem. On the main page I have a search form that is linked to a search script via the action attribute. When the form is submitted it runs the search script and goes to the search.php page. The problem is that I can't seem to style this page. For some reason..all html that I put above the script displays perfectly fine..but anything under the script does not. I am trying to set it up so that the script runs in a certain part of the page so that it only shows the results in that section. Im doing this using div tags in the html but for some reason..I set up the body-home div tag...put the php script in it and close the div. then put the rest of the div tags for the page and everything under the php script wont show.

Can someone please help me figure this out? I'm sure it's something simple.
#issue #php
  • Profile picture of the author Havenhood
    all html that I put above the script displays perfectly fine..
    This is the key to your problem.

    I'd be checking for errors.
    Signature

    --= -Spazzle- =--

    {{ DiscussionBoard.errors[3073431].message }}
  • Profile picture of the author Gclunis
    The script excutes fine when I test it. The only error I receive is a warning "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gclunis/public_html/moodtunez.com/test-site/search.php on line 52" but i'm not sure what that means. I didn't think that would cause all html below the script to not display though. The html is outside of the closing php tag so that error should be read seperately no?
    {{ DiscussionBoard.errors[3073465].message }}
    • Profile picture of the author Havenhood
      Originally Posted by Gclunis View Post

      The script excutes fine when I test it. The only error I receive is a warning "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gclunis/public_html/moodtunez.com/test-site/search.php on line 52" but i'm not sure what that means. I didn't think that would cause all html below the script to not display though. The html is outside of the closing php tag so that error should be read seperately no?
      That means the SQL results are NOT coming through. The result is Empty! Fix that and you should see the display your looking for. If not, I'm around. Not tonight, though!
      Signature

      --= -Spazzle- =--

      {{ DiscussionBoard.errors[3073483].message }}
    • Profile picture of the author CrhisD
      Originally Posted by Gclunis View Post

      The script excutes fine when I test it. The only error I receive is a warning "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gclunis/public_html/moodtunez.com/test-site/search.php on line 52" but i'm not sure what that means. I didn't think that would cause all html below the script to not display though. The html is outside of the closing php tag so that error should be read seperately no?
      You did not successfully connect to the database. Check to see if your server name, user name and password are correct.
      {{ DiscussionBoard.errors[3073509].message }}
  • Profile picture of the author Gclunis
    alright i'll look through it. Thank's so much for the help. I'll let you all know how it works out.
    {{ DiscussionBoard.errors[3073512].message }}
  • Profile picture of the author Gclunis
    Hey guys, so I can't quite figure out what's wrong with the script. Can you guys check it out and get back to me?

    [php]

    <?php



    // Get the search variable from URL

    $var = @$_GET['q'] ;
    $trimmed = trim($var); //trim whitespace from the stored variable

    // rows to return
    $limit=10;

    // check for an empty string and display a message.
    if ($trimmed == "")
    {
    echo "<p>Please tell us how you are feeling...</p>";
    exit;
    }

    // check for a search parameter
    if (!isset($var))
    {
    echo "<p>We dont seem to have a search parameter!</p>";
    exit;
    }

    //connect to your database ** EDIT REQUIRED HERE **
    mysql_connect("localhost","username","password"); //(host, username, password)

    //specify database ** EDIT REQUIRED HERE **
    mysql_select_db("dbname") or die("Unable to select database"); //select which database we're using

    // Build SQL Query
    $query = "select mood from userupload where 1st_field like \"%$trimmed%\"
    order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query

    $numresults=mysql_query($query);
    $numrows=mysql_num_rows($numresults);



    // If we have no results, offer a google search as an alternative

    if ($numrows == 0)
    {
    echo "<h4>Results</h4>";
    echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results please try again.</p>";

    // google
    echo "<p><a href=\"http://moodtunez.com"
    . $trimmed . "\" target=\"_blank\" title=\"Try
    " . $trimmed . " again\">Click here</a> to try the
    search again</p>";
    }

    // next determine if s has been passed to script, if not use 0
    if (empty($s)) {
    $s=0;
    }

    // get results
    $query .= " limit $s,$limit";
    $result = mysql_query($query) or die("Couldn't execute query");

    // display what the person searched for
    echo "<p>Your mood is: &quot;" . $var . "&quot;</p>";

    // begin to show results set
    echo "Results";
    $count = 1 + $s ;

    // now you can display the results returned
    while ($row= mysql_fetch_array($result)) {
    $title = $row["1st_field"];

    echo "$count.)&nbsp;$title" ;
    $count++ ;
    }

    $currPage = (($s/$limit) + 1);

    //break before paging
    echo "<br />";

    // next we need to do the links to other results
    if ($s>=1) { // bypass PREV link if s is 0
    $prevs=($s-$limit);
    print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt;
    Prev 10</a>&nbsp&nbsp;";
    }

    // calculate number of pages needing links
    $pages=intval($numrows/$limit);

    // $pages now contains int of pages needed unless there is a remainder from division

    if ($numrows%$limit) {
    // has remainder so add one page
    $pages++;
    }

    // check to see if last page
    if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

    // not last page so give NEXT link
    $news=$s+$limit;

    echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";
    }

    $a = $s + ($limit) ;
    if ($a > $numrows) { $a = $numrows ; }
    $b = $s + 1 ;
    echo "<p>Showing results $b to $a of $numrows</p>";

    ?>

    [php]

    *The line in question has been put in bold for demonstration purposes
    *username, password, and database name has been blanked
    {{ DiscussionBoard.errors[3073536].message }}
    • Profile picture of the author Havenhood
      The problem looks like it's in this query: $query = "select mood from userupload where 1st_field like \"%$trimmed%\"
      order by 1st_field";

      Are you sure that mood and 1st_field exist in the userupload table?


      if so, try this query.

      $query = "select mood from userupload where 1st_field like '%{$trimmed}%' order by 1st_field";

      I've been up for too long. I've got to get some sleep. Good luck.
      Signature

      --= -Spazzle- =--

      {{ DiscussionBoard.errors[3073667].message }}
  • Profile picture of the author Gclunis
    mood does exist...i didn't know that 1st_field was a value that it was trying to pull. Is 1st_field the primary field?
    {{ DiscussionBoard.errors[3073763].message }}
  • {{ DiscussionBoard.errors[3073771].message }}
  • Profile picture of the author hamrobrt
    I had the same. but it runs sometimes well and sometimes not. might be problem with database
    {{ DiscussionBoard.errors[3073996].message }}
  • Profile picture of the author Jake Gray
    Are you developing on a local machine?
    {{ DiscussionBoard.errors[3075359].message }}
    • Profile picture of the author Havenhood
      Great! Now, change your password.
      Signature

      --= -Spazzle- =--

      {{ DiscussionBoard.errors[3080339].message }}

Trending Topics