Jump to content

Dathremar

Members
  • Posts

    169
  • Joined

  • Last visited

Posts posted by Dathremar

  1. If You can't change the table, I really am out of ideas how to order them by the % of the match.

     

    Maybe try out makeing different query for every search word entered and then count the words that matches and make a display of results by that, but imo that will be a lot of queries and not sure that is a good way to accomplish this. :(

     

    Better try googling for similar search scripts that can help You.

     

    Good luck

  2. $search_parts = explode(" ", $model);
    
    $qry="select * from product_table where ("; 
    $nb_parts = count($search_parts);
    
    for ($i = 0; $i < $nb_parts; $i++)
    {
        $qry .= " ( product_name LIKE '%". $search_parts[$i] ."%') ";
    
        if ($i == $nb_parts-1)
            $qry .= ")";
        else
           $qry .= " OR ";
    }
    $qry .= " ORDER BY product_name DESC";
    

     

    You need to add the order at the end of the query ;)

  3. Dunno how deep are You in this project, but dividing the name field into something like manufacturer + model number will help here i guess.

    But even then I am not sure how are You going to order them by model cuz of simple reason You won't know which of the search words are the model number...

     

    Other idea:

    1.Make a search with LIKE with all the search word by manufacturer

    2. If a match is found, eliminate it from the search

    3. Make a search string and search a match by the model with the other words

    4. Display 1st the results from the 2nd query then from the 1st query.

     

    Another thought:

    Make UNION something like:

     

    qry1="(select *, ordered 2 from product_table where ("; 
    qry2=" UNION (select *, ordered 1 from product_table where ("; 
    $nb_parts = count($search_parts);
    
    for ($i = 0; $i < $nb_parts; $i++)
    {
        $qry1 .= " ( manufacturer LIKE '%". $search_parts[$i] ."%') ";
        $qry2 .= " ( model_nb LIKE '%". $search_parts[$i] ."%') ";
    
        if ($i == $nb_parts-1)
       {
            $qry1 .= ") ";
            $qry2 .= ") ";
       }    
    else
       {
           $qry1 .= " OR ";
           $qry2 .= " OR ";
        }
    }
    
    $main_query = $qry1 . $qry2 . " ORDER BY ordered ";
    

  4. Hmm i am not that good with MySql :/

     

    Adding a sorting of some kind would help here, but not sure what to sort them by.

     

    Can You tell me more info about the table structure please?

  5. Not sure if this is the best way but You could try:

     

    $search_parts = explode(" ", $search_text);
    
    $qry="select * from product_table where ("; 
    $nb_parts = count($search_parts);
    
    for ($i = 0; $i < $nb_parts; $i++)
    {
        $qry .= " ( product_name LIKE '%". $search_parts[$i] ."%') ";
    
        if ($i == $nb_parts-1)
            $qry .= ")";
        else
           $qry .= " OR ";
    }
    

     

     

  6. <?php
    $con = mysql_connect("localhost","xxxxx","xxxxx");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("f1times_articles", $con);
    
    $result = mysql_query("SELECT * FROM n2s_article ORDER BY article_id DESC LIMIT 0,15");
    
    echo "<table border='0'>
    <tr>
    <th>Latest News</th>
    </tr>";
    
    while($row = mysql_fetch_array($result))
      {
        $url = $row['article_url'] . "-" . $row['article_id'] . ".html";
        echo "<tr>";
        echo "<td><h2><a href='$url'>".stripslashes($row['article_title'])."</h2></a>";
        echo "<p>{$row['article_teaser']}</p></td>";
        
      }
    
    mysql_close($con);
    ?>
    

     

    You trying it like this?

  7. SELECT * from table WHERE thedate > todays date will give You the dates that are larger then today's date.

    Do you have that kind of record?

     

    Maybe try: SELECT * from table WHERE thedate >= todays date;

     

    And try printing out "thedate" to see if the format matches

  8. Hmm If i get You right

     

    $percentage = 25;  // Put here the random number for dynamic percentage
    $act1c = 0;
    $act2c = 0;
    
    for ($i = 1; $i <= $percentage; $i++){
    $action = $action1;
    $act1c++;
    }
    
    for ($j = $percentage; $j <= 100; $j++){
    $action = $action2;
    $act2c++;
    }
    
    

     

    Is this better or I am still missing the point :S

     

  9. Before You do the insert into database do a check if the username already exists, something like:

     

    "SELECT table_id FROM users WHERE username = '$your_input_var'"

     

    If this statement returns number of rows > 0 then print out "Sorry this username has already been taken"

     

    Hope this helps

  10. The problem with:

     

    $this->uploadLocation = $_SERVER['DOCUMENT_ROOT'] . "static/gallery/products/" . $_GET['id'];

     

    is the missing "/" in the path. Like ToonMariner said he is not sure if $_SERVER['DOCUMENT_ROOT'] has "/" or not ;)

     

  11. Put id on that <li> tags and then use Java Script to put the "active" class on your selected link.

     

    For the java script part:

    document.getelementbyid(id_changed).className = newClass;

    document.getelementbyid(id_previous).className = ""; // or some other class

     

    Also another option is if You reload the page do that with php.

     

  12. <?php
    
    //Get DB configuraion file
    require('./config/config.php');
    
    
    //Set variables
    $species = $_POST['species'];
    $location = $_POST['location'];
    $state = $_POST['state'];
    $date = $_POST['date'];
    $comments = $_POST['comments'];
    
    if (isset($_FILES['image']['tmp_name']))
    {
    //Check file is a valid image and under 200kb
    if (($_FILES["image"]["type"] == "image/jpeg") && ($_FILES["image"]["size"] < 200000))
       {
    		//prepare the image for insertion
    		$image =addslashes (file_get_contents($_FILES['image']['tmp_name']));
    	}
    	else
    		echo "Sorry, your image is more then 200KB or you have entered an invalid file type (.jpg only)";
    }
    else
    $image = 'NULL';	
    
    //Insert into database
    $sql="INSERT INTO bird_db (image, species, location, state, date, latlong, comments)
    VALUES ('$image', '$species', '$location', '$state', '$date', '$latlong', '$comments')";
    
    if (!mysql_query($sql))
       {
    die('Error: ' . mysql_error());
       }
    else
    echo "Thank you, your record has been added to the database"; 	
    
    }
    ?>
    

    Try this.

     

    P.S Not tested for errors

  13. function getExtension($str) {

            $i = strrpos($str,".");  // Position of the "." in the string, if there is one

            if (!$i) { return ""; }

            $l = strlen($str) - $i;  // The length of the string subtract the position of the "."

            $ext = substr($str,$i+1,$l); // gets the extension

            return $ext;

    }

     

    But to be honest I would just use explode function. Something like this:

     

    function getExtension($str) {
           $parts_string =  explode( ".", $str ) 
           if (count($parts_string) > 1)
              return $parts_string[1];
           else
             return ""; 
    }
    

×
×
  • 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.