Jump to content

Bazzaah

Members
  • Posts

    49
  • Joined

  • Last visited

Posts posted by Bazzaah

  1. Hi there

     

    I adapted the pagination tutorial from here on PHP Freaks so that it can deal with a db query.

     

    The pagination itself works just fine but I have a small issue, hopefully someone can help me please.

     

    I have set up the query so that it won't allow blank searches. The script works perfectly well without the pagination.

     

    With the pagination, the script now returns a few results as well as the 'you didn't enter a search-term' message - can someone help me tidy it up please? I'm guessing that I've put the search=$search term in too many places in the pagination script.

     

    This is the query

     

    if (isset($_GET['search'])) {
    $searchTerms = trim($_GET['search']);
    $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
       
    if (strlen($searchTerms) < 1) {
          $error[] = '<div class="messagebox">You didn\'t specify a search term</div></div>';
          $error[] = '<div class="small"><a href="search2.php"><p>Search Again?</p></a></div>';
       } else {
          $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
       }
    
    $sql = "SELECT * FROM pro_words WHERE word LIKE '%{$searchTermDB}%' ORDER BY word LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
    $num_rows = mysql_num_rows($result);
    
    //display results
    
    if (mysql_num_rows($result) < 1) {
             $error[] = '<div class="messagebox">Sorry, your search term yielded no results.</div>';
             $error[] = '<div class="small"><a href="search.php"><p>Search Again?</p></a></div>';
          } else {
          echo '<div class="messagebox">Here are your search results.</div>';		
    
    	while ($list = mysql_fetch_array($result)) {
       // echo data
    echo '<div class="small"><a href="word.php?w=' . $list['word'] . '">' . $list['word'] . '</a></div>';  
      } //end while	
    
      			}	
    	}	
    

     

    This is the pagination

     

    // range of num links to show
    $range = 3;
    
    // if not on page 1, don't show back links
    if ($currentpage > 1) {
       // show << link to go back to page 1
       echo " <a href='{$_SERVER['PHP_SELF']}?search=$search&currentpage=1'><<</a> ";
       // get previous page num
       $prevpage = $currentpage - 1;
       // show < link to go back to 1 page
       echo " <a href='{$_SERVER['PHP_SELF']}?search=$search&currentpage=$prevpage'><</a> ";
    } // end if 
    
    // loop to show links to range of pages around current page
    for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
       // if it's a valid page number...
       if (($x > 0) && ($x <= $totalpages)) {
          // if we're on current page...
          if ($x == $currentpage) {
             // 'highlight' it but don't make a link
             echo " [<b>$x</b>] ";
          // if not current page...
          } else {
             // make it a link
             echo " <a href='{$_SERVER['PHP_SELF']}?search=$search&currentpage=$x'>$x</a> ";
          } // end else
       } // end if 
    } // end for
                     
    // if not on last page, show forward and last page links        
    if ($currentpage != $totalpages) {
       // get next page
       $nextpage = $currentpage + 1;
        // echo forward link for next page 
       echo " <a href='{$_SERVER['PHP_SELF']}?search=$search&currentpage=$nextpage'>></a> ";
       // echo forward link for lastpage
       echo " <a href='{$_SERVER['PHP_SELF']}?search=$search&currentpage=$totalpages'>>></a> ";
    } 
    

     

    Thanks in advance for any help.

  2. Hi

     

    I have a question, hope someone can help me please.

     

    If have a header and container set up like this;

     

    /* header */
    
    #header {
    position: absolute;
      	top:0;
      	left:0;
      	width:100%;
    }
    
    /* container  */
    
    #container{
    position: absolute;
    margin-left: auto;
    margin-right: auto;
    width: 950px;
    margin-top: 120px;
    }
    

     

    The header goes where it should be but the container is stuck on the left margin, but with the margin-left and margin-right set to auto, I thought the container should be centered. I'd like the centering to be automatic as I'm using a fixed width.

     

    Any ideas on why that's not happening?

     

    If you need further info to help then please say.

     

    Thanks in advance for any help

  3. Hey there

     

    I've adapted the search code from the tutorial on this site here

     

    http://www.phpfreaks.com/tutorial/simple-sql-search

     

    for a project I've been working on but have an error.

     

    The search works just fine but if either of the messages I've included are tripped (zero search characters or nothing found) then I get a blank screen and the error message is not echoed. (The vanilla code works fine - the error has arisen through the changes I needed to make).

     

    I don't know why this is happening and would appreciate some help please.

     

    Thanks in advance for any help.

     

    session_start();
    
    // check session variable
    
    if (isset($_SESSION['first_name']))
      {
    include ('includes/header_loggedin.html');
    
    //db connection info deleted  
    
    $error = array();
    
    //get search term, strip it
    
    if (isset($_GET['search'])) {
    $searchTerms = trim($_GET['search']);
    $searchTerms = strip_tags($searchTerms); // remove any html/javascript.
    
       
       if (strlen($searchTerms) < 1) {
          $error[] = 'Search terms must be longer than 1 character.';
       }else {
          $searchTermDB = mysql_real_escape_string($searchTerms); // prevent sql injection.
       }
       
    //formulate query
       if (count($error) < 1) {
    $query = "SELECT * FROM table WHERE row LIKE '%{$searchTermDB}%'";
    
    //make the query
    
    $result = mysql_query($query) or die(mysql_error());
    
    //display the results
    if (mysql_num_rows($result) < 1) {
             $error[] = "Your search term yielded no results.";
          } else {
    	while ($endresult = mysql_fetch_array($result)) {
    		echo '<br />';
    		echo 'This is what we found';
    		echo '<br />';
          echo '<a href="newpage.php?w=' . $endresult['row'] . '">' . $endresult['row'] . '</a>';
      		}	
    }
    }
    }
    } 
    

  4. I'd appreciate some help please.

     

    I'm using $_SESSION to pass info from a MySQL search to a new page.

     

    How do I include the $_SESSION in the SELECT? I've done loads of different combinations - none has worked and I've not found anything to help on Google.

     

    In this case;

     

    user searches a db table.

    Results are returned.

    User can click on result to be taken to a new page where columns from the row are displayed

     

    Results are displayed on the new page like this;

     

    $query = "SELECT * FROM table";  
    
    $result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_assoc($result)){
    
    echo $_SESSION[$column] ;
    
    }
    

     

    That code returns the correct column BUT for as many rows there are in the table.

     

    How can I  set things up so that column entries are only echoed for the one row that's been selected by the user?

     

    Sorry if unclear; happy to clarify if needed - any help would be really appreciated.

  5. Thanks for that.

     

    I should have said that the facility can only be used by registered users - there's already a session variable in existence for the user; where does that leave the session variable you create?

     

    I popped that code you kindly provide into the relevant files but doesn't seem to have an effect..I wonder if I'm missing something - is there any significance behind your calling 'where_clause'?

     

    Thanks

  6. Hi

     

    Hope someone can help me please.

     

    I have constructed an audio dictionary and have discovered an error now that I have added a few entries to the database.

     

    A user can search the database and can click on a result to be taken to the content associated with the entry he chooses.

     

    This is the search function;

     

    $search=$_POST["search"];
    
    
    //get the mysql and store them in $result
    
    $result = mysql_query("SELECT word FROM pro_words WHERE word LIKE '%$search%'");
    		        
    //get the db content that is specified above
    
    if (mysql_num_rows($result) < 1) {
    
    echo "<br><br><h2> We didn't find anything. Sorry - we did look though.</h2>";
    
    }else {
             
    echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr><td align="left"><b>Word</b></td></tr>';
    
    echo "<br><br><h2>Success! Here's what we found:</h2><br>";
    
    while ($r=mysql_fetch_array($result, MYSQLI_ASSOC))
    
    echo '<h2><tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr></h2>';
    
    }
    

     

    You will see that content is displayed in a new file called word.php.

     

    This is relevant code from word.php

     

    
    $query = "SELECT word,word_type1,sentence1,word_type2,sentence2,word_type3,sentence3 FROM pro_words"; 
    
    $result = mysql_query($query) or die(mysql_error());
    
    while($row = mysql_fetch_array($result)){
    
    
    echo '<div class="colmask rightmenu">';
    echo '<div class="colleft">';
    echo '<div class="col1">';
    echo '<p>Here are some example sentences that show how we use the word; </p>';
    echo '<div id="small"><i> ' . $row['word_type1'] . '</i></div>';	
    echo '<p><div id="small">' . $row['sentence1'] . '</p></div>';
    echo '<div id="small"><i> ' . $row['word_type2'] . '</i></div>';
    echo '<p><div id="small">' . $row['sentence2'] . '</p></div>';
    echo '<div id="small"><i> ' . $row['word_type3'] . '</i></div>';
    echo '<p><div id="small">' . $row['sentence3'] . '</p></div>';
    
    }
    

     

    The problem is that every entry on the database is echoed in word.php whereas I would like only the entries for the word selected to appear.

     

    Thanks in advance for any help; do say if you need more info.

     

     

  7. Hi

     

    I hope someone can help me please.

     

    I am using a media player to stream MP3s in an audio dictionary.

     

    Words and sentences are generated through a MySQL search.

     

    I would like the media player to appear alongside the search result

     

    This is example code for echoing the search result

    echo '<p><div id="small">' . $row['sentence1'] . '</p></div>';
    

     

    This is the code for the media player

    <object type="application/x-shockwave-flash" data="/player/dewplayer.swf" width="200" height="30" id="dewplayer" name="dewplayer">
    <param name="movie" value="/player/dewplayer.swf" />
    <param name="flashvars" value="mp3=' . $row['wordfile'] . '" />
    <param name="wmode" value="transparent" />
    </object>
    

     

    So basically I'm looking for the results to echoed then the player to appear next to the search result.

     

    Any help would be much appreciated

     

    Thanks in advance

     

  8. Hi

     

    I'm building a site that contains access to some mp3 files of people speaking English.

     

    I would like a media player that is able to handle a variable that results from a database search.

     

    I can use  <a href etc> to link to the relevant file but would like to use a server-side player to stream the file, rather than the client's browser.

     

    Something like Dewplayer would be perfect but it seems only to take a static file (maybe I'm wrong there).

     

    The player appears within <object> tags, like this

     

    <code>

    echo '<object type="application/x-shockwave-flash" data="/player/dewplayer.swf" width="200" height="30" id="dewplayer" name="dewplayer">';

    echo '<param name="movie" value="/player/dewplayer.swf" />';

    echo '<param name="flashvars" value="mp3=file.mp3" />';

    echo '<param name="wmode" value="transparent" />';

    echo '</object>';

    </code>

     

    (the code is freely downloadable so hope I'm not breaking any rules posting someone else's code here).

     

    Is there a way I can specify a variable in value? If not, does anyone know of a player that I can use that does allow that?

     

    Grateful for any help.

     

    Thanks in advance.

     

  9. Hi

     

    I have a small problem and would be grateful for some help please.

     

    I've been working on an audio dictionary.

     

    The dictionary contains a search function;

     

    $result = mysql_query("SELECT word,sentence1 FROM pro_words WHERE word LIKE '%$search%'");

     

    The results from the search are displayed as links to a new file.

     

    echo '<tr><td align="left"><a href="word.php?w=' . $r['word'] . '">' . $r['word'] . '</a></td></tr>';

     

    Is there a way I can get the file word.php to include other information from the database entry, for example sentence1?

     

    I've been puzzling over this and haven't found a way to make it work, even though it seems like it should be straightforward.

     

    Hope the question is clear and thanks in advance for any help.

  10.  

    I actually thought it was a file that I need to put on the server but I opted to ask a stupid question instead!

     

    I think I can figure the rest out now but thanks for your help, I really appreciate it.

     

    How does one mark a thread as solved?

  11. that's exactly what I meant, thanks!

     

    I'll need to sort out the links as I get a 404 when I click on the search results, but it looks exactly right!

     

    I have a question on the syntax - <a href="word.php?w=..." - I take it word.php is produced dynamically as a result of the query?.

     

    Thanks for your help.

     

     

  12. I'd appreciate some help please.

     

    I am building an audio dictionary and have written a working search function.

     

    I would like the search to return a link to the relevant audio file, so that if someone searches for a word in the database they can click on the link to stream that file via their browser.

     

    I have set the database to link to files stored in the site's main folder.

     

    So far drawn a blank with my various efforts.

     

    This is what I have  currently;

     

     
    
    <?php
    
    $result = mysql_query("SELECT word,sentence1 FROM pro_words WHERE word LIKE '%$search%'");
    					        
    //get the db content that is specified above
    
    if (mysql_num_rows($result) < 1) {
    
    echo "<h2>Sorry, but your search did not yield any results.</h2>";
    
    }else {
             
    echo '<table align="center" cellspacing="8" cellpadding="8" width="85%"><tr>
    <td align="left"><b>Word</b></td><td align="left"><b>Example of usage</b></td></tr>
    ';
    
    echo "<h3>This is what we found:</h3><br>";
    
    while ($r=mysql_fetch_array($result, MYSQLI_ASSOC))
    
    echo '<tr><td align="left">' . $r['word'] . '</td><td align="left">' . $r['sentence1'] . '</td></tr>';
    
    }
    
    echo '</table>'; // Close the table.
    
       }
    
    ?>
    
    

     

    It works fine as a search function and I have tried adding various iterations around <a href> where the code echoes the search output but without success.

     

    Any help would be very much appreciated.

     

    Thanks in advance

  13. Hi

     

    Gnone - Mint is way more complete than Ubuntu out of the box and the Mint guys spend a good while debugging Ubuntu.

     

    KDE - Mandriva 2010 when that comes out in a couple of weeks (I use the RC2 at the moment and it works great).

     

    Will you use onboard sound? If you think about buying a sound card, just check on ALSA support before you buy.

     

     

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.