Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

php web page ..& MySQL DB

Options
  • 18-06-2007 9:24am
    #1
    Closed Accounts Posts: 1,788 ✭✭✭


    I have a small php personal project i am doing, it's a film library,
    I have a list of films on a page, which is just a select title FROM films..

    I want each of these titles to be a link to another page
    that shows all details of this film (SELECT * from films where title = xxx)

    Now , I can do this with forms using the POST method, but i dont wanna have buttons beside the film title, it's better to just use the links ...
    is there a way of using links to pass the argument (in this case film title)..


Comments

  • Registered Users Posts: 14,761 ✭✭✭✭Winters


    You can pass them through the query string:

    eg: <a href="film.php?title=YOUR FILM TITLE">link</a>

    and on the php side of things:
    $film_title = $_GET;
    "SELECT * from films where title = ". $film_title;

    However, passing films titles like that through the querystring isint the best idea. Id probably reccomend using the autoincrement id from the database which would prevent any confusin in films with two names etc.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    jackdaw wrote:
    is there a way of using links to pass the argument (in this case film title)..
    Yes, send the film ID using a HTTP GET rather than POST. (e.g. "showfilm.php?id=32" which would be picked up using $_GET["id"]).

    Edit: Actually Winters put it more clearly.


  • Closed Accounts Posts: 1,788 ✭✭✭jackdaw


    ok yeah better id , I do have a primark key ID in the film DB i can use that ..
    so ill have something like :

    <a href = "film_detailed.php?title=$row> <?php print_r($row." ".$row);


  • Closed Accounts Posts: 97 ✭✭koloughlin


    One side comment.... It's probably better to avoid the "select *" construct in your code. Instead put the actual field names you will use. The reason is that if you every add another field to your table you may have to go back through all your code to change it to handle the new field. If you select only the field names you need then you only have to modify the code which needs to deal with the new field.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    koloughlin wrote:
    The reason is that if you every add another field to your table you may have to go back through all your code to change it to handle the new field. If you select only the field names you need then you only have to modify the code which needs to deal with the new field.
    That makes no sense. If he adds new fields and wants to display or otherwise use them he'll have to go back to his code and change is regardless. Indeed, if he uses a table wildcard, then at least he won't have to add the field in his SQL select.


  • Advertisement
  • Closed Accounts Posts: 97 ✭✭koloughlin


    That makes no sense. If he adds new fields and wants to display or otherwise use them he'll have to go back to his code and change is regardless. Indeed, if he uses a table wildcard, then at least he won't have to add the field in his SQL select.

    You're probably correct. I was thinking that he might be just looping through the fields in the result set to display all columns returned. That would probably be considered an even worse thing to do :). That way he adds a new field to his table to hold the credit card number he used to buy his movies and it suddenly appears on his web page.

    My own experience is more on the data warehousing/data movement side. In that field you want to keep the data you move as lean as possible. There can be a lot of unnecessary overhead created by doing select *. Consider a table with BLOB or CLOB fields that you don't need to use in your application. By doing select * you will end up pulling these data across the network unnecessarily.

    Sometimes 'select *' can even break your code. An example is if you've got a union in your code
    select * from table1 union all select * from table2
    

    This will work until the day someone adds a field to one table but not to the other.

    I tried to google to find some articles on this, but google tends to ignore the '*' character so it was hard to find anything.

    Anyway here are a couple of links
    http://www.russellbeattie.com/notebook/1007886.html
    http://searchoracle.techtarget.com/ateQuestionNResponse/0,289625,sid41_cid576581_tax301455,00.html
    http://www.joelango.com/2007/04/30/why-you-should-never-use-select-star/

    In any case it probably doesn't make much difference for a home grown application where change management and performance aren't really issues. It just raised a red flag with me because I've seen it break things before.


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    I don't disagree that the use of select wild cards should be avoided as a rule, only questioned your initial reasoning behind it. In the OP's case I doubt that any of the scenarios you've presented would be issues as I suspect it is a very simply application - on the other hand it wouldn't kill him to use good coding practices either ;)


  • Closed Accounts Posts: 1,788 ✭✭✭jackdaw


    Is there a way of combining POST & GET data ?

    passing them both to a page ?

    I need to "Borrow" a film, and i click a film from the list, I can then update a flag in the DB that specifies whether film is on loan or not.(been using GET). but I also want to pass the name of the Borrower.. (POST)
    I seem to be only able to update the loan_Flag .. I can't seem to combine GET & POST in the same page...


Advertisement