Groups

    Web design help : im stumped for once lol

    ok im inserting data into a database that anyone can view using the search function i built on, but i have no idea how to make the data (gonna be links to websites) clickable links/


    e,g, basically its a more subtle version of google Lol

    lot more basic for time being

    17 Comments

    same way you make anything a clickable link...

    Link text

    replacing linkUrl and link text with the data from your database.

    Original Poster

    chrishill;3835878

    same way you make anything a clickable link...Link textreplacing linkUrl … same way you make anything a clickable link...Link textreplacing linkUrl and link text with the data from your database.



    i tried that and got a mysql error ..... thats the first thing i tried :lol:

    unless im using the wrong data type ...... im using varchar

    Banned

    Is it the movie Passenger 57 starring Hollywood's Wesley Snipes?

    What scripting language are you using?

    If you're using php then you'll need this: uk.php.net/mys…ing

    faevilangel;3835888

    i tried that and got a mysql error ..... thats the first thing i tried … i tried that and got a mysql error ..... thats the first thing i tried :lol:unless im using the wrong data type ...... im using varchar



    Datatype probably won't make any difference, although I'd use 'text' since its possible your URL's or page descriptions could run to longer than 255 characters (varchar's limit).

    A mySQL error probably means theres an issue with your SQL statement rather than the HTML.

    This won't fix it for you since its mostly pseudo code, but it should give you some hints. I've also added comments.


    $query = "SELECT * FROM tableName WHERE columnName LIKE 'string';"; // this tells the database to go off and find all rows in the specified table where the data in the specified column matches the string, so it could be WHERE id LIKE '1' or WHERE name LIKE 'Tarquin'.

    $result = mysql_query($query)
    or die ("couldnt execute query".mysql_error()); //send the query to the dB and put the results in a variable called '$result' or return an error if theres a problem

    while ($row = mysql_fetch_array($result)) // while $result contains data (ie, while the dB is returning data from the query) do the following
    {
    $linkList_HTML = "url'])."'>".html_entity_decode($row['linkText'])."
    ";
    }

    // this last bit creates a string which contains the html for links with the results from the dB in the relivant places. The html_entity_decode bit is worth remembering since whenever you put data in to a dB you really need to encode it to convert all special symbols in to their HTML equivalent codes (such as & becoming &). html_entity_decode reverses this encoding.

    // finally...

    echo $linkList_HTML; //shows the list of links on screen.

    megalomaniac;3835981

    What scripting language are you using?If you're using php then you'll … What scripting language are you using?If you're using php then you'll need this: http://uk.php.net/mysql_real_escape_string



    thats for inserting data.

    Banned

    chrishill;3842084

    Datatype probably won't make any difference, although I'd use 'text' … Datatype probably won't make any difference, although I'd use 'text' since its possible your URL's or page descriptions could run to longer than 255 characters (varchar's limit).A mySQL error probably means theres an issue with your SQL statement rather than the HTML.This won't fix it for you since its mostly pseudo code, but it should give you some hints. I've also added comments.$query = "SELECT * FROM tableName WHERE columnName LIKE 'string';"; // this tells the database to go off and find all rows in the specified table where the data in the specified column matches the string, so it could be WHERE id LIKE '1' or WHERE name LIKE 'Tarquin'.$result = mysql_query($query) or die ("couldnt execute query".mysql_error()); //send the query to the dB and put the results in a variable called '$result' or return an error if theres a problemwhile ($row = mysql_fetch_array($result)) // while $result contains data (ie, while the dB is returning data from the query) do the following{ $linkList_HTML = "url'])."'>".html_entity_decode($row['linkText'])."";}// this last bit creates a string which contains the html for links with the results from the dB in the relivant places. The html_entity_decode bit is worth remembering since whenever you put data in to a dB you really need to encode it to convert all special symbols in to their HTML equivalent codes (such as & becoming &). html_entity_decode reverses this encoding.// finally...echo $linkList_HTML; //shows the list of links on screen.


    I think you mean = rather than LIKE

    LIKE is for pattern matching (e.g columname LIKE 'TAR%', columname LIKE 'TAR_UIN' )

    Use IN for list value matches and use BETWEEN for a range. :thumbsup:

    chrishill;3842086

    thats for inserting data.



    From the OP: "ok im inserting data into a database " :whistling:

    How about showing us some of the code?

    megalomaniac;3842196

    From the OP: "ok im inserting data into a database " :whistling:



    Hes wanting to turn the data in to clickable links, which should be done at the output stage.

    csiman;3842160

    I think you mean = rather than LIKELIKE is for pattern matching (e.g … I think you mean = rather than LIKELIKE is for pattern matching (e.g columname LIKE 'TAR%', columname LIKE 'TAR_UIN' )Use IN for list value matches and use BETWEEN for a range. :thumbsup:



    nope, i mean 'LIKE'. Most mysql/php tutorials you see will give you statements using LIKE unless you explicitly go looking for ones that use 'IN'.

    Lets not start waving our coding willys though eh? its not going to help faevilangel.

    Banned

    chrishill;3842437

    Hes wanting to turn the data in to clickable links, which should be done … Hes wanting to turn the data in to clickable links, which should be done at the output stage.nope, i mean 'LIKE'. Most mysql/php tutorials you see will give you statements using LIKE unless you explicitly go looking for ones that use 'IN'.Lets not start waving our coding willys though eh? its not going to help faevilangel.


    then the tutorials are lazy as its inefficient to use LIKE when you explicitly know the search variable

    csiman;3842487

    then the tutorials are lazy as its inefficient to use LIKE when you … then the tutorials are lazy as its inefficient to use LIKE when you explicitly know the search variable



    its debatable if the search variable is a known element in this instance. I doubt it, since the op suggested search engine functionality which would, IMO, constitute a need for pattern matching rather than exact string matching.

    Banned

    chrishill;3842656

    its debatable if the search variable is a known element in this instance. … its debatable if the search variable is a known element in this instance. I doubt it, since the op suggested search engine functionality which would, IMO, constitute a need for pattern matching rather than exact string matching.


    yes, I take your point although the example you gave had a fixed constant.

    Damn! Feel like I'm back at work. Used to be a cobol/db2 programmer for 25 years until technology overtook my skillset (and my age lol) ;-)

    chrishill;3842656

    its debatable if the search variable is a known element in this instance. … its debatable if the search variable is a known element in this instance. I doubt it, since the op suggested search engine functionality which would, IMO, constitute a need for pattern matching rather than exact string matching.



    You're right, LIKE isn't particularly powerful though, by the sounds of what he's trying to do regular expressions are much more suitable.

    Original Poster

    thanks for the info chris .......... im normally pretty dandy with sql but this stumped me :lol: didnt think it would be that simple :w00t:

    basically the idea is an ajax search engine, which the user can add links to the database (its a small scale for a website by itself (not a full on search engine (yet))

    i really did think i may have to use some php coding to make the data from the db, be outputted as a link, darn me for thinking beynd the lines :lol:

    i will change my data type to text to see if that solves the problem

    csiman;3842956

    yes, I take your point although the example you gave had a fixed … yes, I take your point although the example you gave had a fixed constant.Damn! Feel like I'm back at work. Used to be a cobol/db2 programmer for 25 years until technology overtook my skillset (and my age lol) ;-)



    ;-) you'll have to excuse my hasty early morning sloppy code for that. I'd imagine theres still a call for people who can code complex sql is there not? My skills are purely web-based and self taught over the 10 years I've been doing this and I'd consider myself an amateur with SQL, my complex joins are bl**dy horrible! I really only learn what my job requires me to know, I've no time for anything else at the moment!

    megalomaniac;3842963

    You're right, LIKE isn't particularly powerful though, by the sounds of … You're right, LIKE isn't particularly powerful though, by the sounds of what he's trying to do regular expressions are much more suitable.



    regex... *shudder* no need to swear ;-) You're right, though I think we're over complicating things for now.

    faevilangel;3843068

    thanks for the info chris .......... im normally pretty dandy with sql … thanks for the info chris .......... im normally pretty dandy with sql but this stumped me :lol: didnt think it would be that simple basically the idea is an ajax search engine, which the user can add links to the database (its a small scale for a website by itself (not a full on search engine (yet)) i really did think i may have to use some php coding to make the data from the db, be outputted as a link, darn me for thinking beynd the lines i will change my data type to text to see if that solves the problem



    Personally I'd store the url, page title and a page description in three columns in the dB. Use the SQL query to match the search terms a visitor enters to the page description (and possibly title too) then return the urls. loop through the results and add the html to turn them in to links.

    I'm not saying thats the absolute, final, one and only correct way of doing it - google certainly doesn't work that way and it'll require management on your part to create the page descriptions - but for what you're trying to do, thats how I'd do it.

    good luck!

    Original Poster

    chrishill;3843180

    ;-) you'll have to excuse my hasty early morning sloppy code for that. … ;-) you'll have to excuse my hasty early morning sloppy code for that. I'd imagine theres still a call for people who can code complex sql is there not? My skills are purely web-based and self taught over the 10 years I've been doing this and I'd consider myself an amateur with SQL, my complex joins are bl**dy horrible! I really only learn what my job requires me to know, I've no time for anything else at the moment!regex... *shudder* no need to swear ;-) You're right, though I think we're over complicating things for now.Personally I'd store the url, page title and a page description in three columns in the dB. Use the SQL query to match the search terms a visitor enters to the page description (and possibly title too) then return the urls. loop through the results and add the html to turn them in to links.I'm not saying thats the absolute, final, one and only correct way of doing it - google certainly doesn't work that way and it'll require management on your part to create the page descriptions - but for what you're trying to do, thats how I'd do it.good luck!



    i was going to make it a basic search for now but add something called the "stemmer" onto the database query in the near future .......

    im thinking thats the way to go for the time being ...... just insert the link as html code into the db
    Post a comment
    Avatar
    @
      Text
      Top Discussions
      1. Shana Tova to all Jewish HUKDers2030
      2. HUKD Satellite Information & IPTV Thread48710954
      3. So Brexit isn't going how a lot of Brexiters thought it would917
      4. What would be HELL to you?2944

      See more discussions