Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    PHP Search Mysql no results found

    Hello,
    This is my first venture into php. I was asked by my employer to make a search page to search a database that contains the fields id, school, name, position, extension, email. I followed a few tuts and I keep getting no results found. Any help would be greatly appreciated! I know I'm connecting to the database correctly in the code. I just didn't want to display that info. thanks!

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    </head>
    
    <?php
    
    //get data
    //$button = $_GET['submit'];
    
    $search = $_GET['search'];
    
    
        {
        if (strlen($search)<=2)
    		echo "Search term too short.";
    	else
    	
    		echo "You searched for <b>$search</b><hr size='1'>";
    		
    		//connect to database
    		mysql_connect("","","");
    		mysql_select_db("dubuque_cms");
    		
    		
    				//explode search term
    				$search_exploded = explode(" ",$search);
    				
    				foreach($search_exploded as $search_each)
    				{
    					//query
    				    $x++;
    					if ($x==1)
    						$construct .= "name LIKE '%$search_each%'";
    					else
    						$construct .= "OR name LIKE '%$search_each%'";
    				}
    			
    		//echo out contstruct
    		
    		$construct = "SELECT * FROM phonelist WHERE $construct";
    		$run = mysql_query($construct);
    		
    		$foundnum = mysql_num_rows &run;
    		
    		if ($foundnum==0)
    			{echo "No results found. Search again.";}
    		else
    		{
    			echo "$foundnum result(s) found!<p>";
    			
    			while ($runrows = mysql_fetch_assoc &run)
    			{
    			//get data
    			$school = $runrows['school'];
    			$name = $runrows['name'];
    			$position = $runrows['position'];
    			$extension = $runrows['extension'];
    			$email = $runrows['email'];
    			
    			echo
    			"<br>$school</b><br>$name</br><br>$position</br><br>$extension</br><br>$email<p>";
    			}
    		
    		}
    		
    	}
    
    
    
    ?>
    </html>
    EDIT: I see I forgot two curly brackets...
    Last edited by iadubber; 06-01-2011 at 05:01 PM.

  • #2
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    after fixing the curly brackets I am getting

    Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM in /home/dubuque/public_html/testing/searchphonelist.php on line 46

    Line 46 is...$foundnum = mysql_num_rows (&run);

    What's wrong in that line? I deleted the () and now I still get no results found.
    Last edited by iadubber; 06-01-2011 at 05:02 PM.

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,338
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    T_PAAMAYIM_NEKUDOTAYIM is a double colon - ::

    PHP gets its line numbers confused with some errors. You can't be guaranteed the problem is line 46.

    Next you're not using brackets properly:
    PHP Code:
    //Wrong and you should use $ not &
    $foundnum mysql_num_rows &run;

    //Correct
    $foundnum mysql_num_rows($run);

    //Also wrong - use parenthesis and $
    while ($runrows mysql_fetch_assoc &run)

    //Correct
    while ($runrows mysql_fetch_assoc($run)) 
    Next please use [php] tags for your php code - you've seen why above (link in my signature).

    Also you might want to check out my styling link too as your indents are a bit excessive. If you use notepad++ you can replace a tab with spaces instead - i have mine set to 3 spaces which works very well and keeps everything visible with no scrolling needed.
    Last edited by tangoforce; 06-01-2011 at 05:20 PM.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  • Users who have thanked tangoforce for this post:

    iadubber (06-01-2011)

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tangoforce View Post
    T_PAAMAYIM_NEKUDOTAYIM is a double colon - ::

    PHP gets its line numbers confused with some errors. You can't be guaranteed the problem is line 46.

    Next you're not using brackets properly:
    PHP Code:
    //Wrong and you should use $ not &
    $foundnum mysql_num_rows &run;

    //Correct
    $foundnum mysql_num_rows($run);

    //Also wrong - use parenthesis and $
    while ($runrows mysql_fetch_assoc &run)

    //Correct
    while ($runrows mysql_fetch_assoc($run)) 
    Next please use [php] tags for your php code - you've seen why above (link in my signature).

    Also you might want to check out my styling link too as your indents are a bit excessive. If you use notepad++ you can replace a tab with spaces instead - i have mine set to 3 spaces which works very well and keeps everything visible with no scrolling needed.
    DOH! Those & and $ got me! It works now and I thank you so much!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •