www.webdeveloper.com
Results 1 to 2 of 2

Thread: php/mysql newbie | help

  1. #1
    Join Date
    Sep 2013
    Posts
    1

    php/mysql newbie | help

    Hello everyone,

    I have a problem regarding PHP/MySQL.
    I've been learning PHP, along with HTML/CSS/jQuery (jQuery just started), for a month now, without any prior programming/markup experience, so be soft here. :P

    Anyways, I've come across a problem I can't solve and I'd be grateful if someone here can solve it for me. I have a leaning more towards the front-end development, so I kinda suck at PHP (haven't really done anything in more than a week), but I would like to know the basics at least. Hope someone answers, thank you in advance.

    Problem:

    Let's say we have a database called 'store', a table called 'movies' and a table called 'reservations'. I need to create a .php page with movie titles (let's say the column is named 'movienames') sorted alphabetically, for example:

    Almost Famous
    American History X
    Apocalipse Now
    .
    .
    .

    I should create a link on every title that leads to another page we can call 'reservations.php'. There, we should list the schedule of reservations for a certain movie. Obviously, there should be a primary key ('movienames') from movies in 'reservations' as a secondary key. We should also have a date column, let's call it 'resDate' and one more secondary key from another table (video store users for example) we can call 'users'. We should format it like this:

    Almost Famous
    Monday, Marko
    Saturday, Eric
    Sunday, Ivan
    .
    .
    .

    That's basically it, I should also have a link on 'reservations.php' that leads to the main page we can call 'index.php'.

    Thx again!

    P.S. I'm sure it's an easy task for you, but I'm really awful at PHP and I neglect it whenever I can.

  2. #2
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    509
    Without learning php the kind of thing you are describing will be pretty hard to achieve. The sql to extract that data will be easy and the html to display the results will be easy, but you need to use php to put the two tasks together and end up with what you want.

    Query 1
    Code:
    $q = "select * from movies order by movienames";
    $pdo = (do your db connection);
    $qrslts = $pdo.query($q);
    This query will pull all your movie titles sorted alphabetically.

    When designing your tables, I'd assign a key to the movies table other than the title. An autoinc field would work, then use that key as the link to the reservations table.

    With the results of the query above your php code to generate your first page would be:

    [code]
    while ($row = $qrslts.fetch(PDO::FETCH_ASSOC))
    {
    // simple display of movie names with builtin links
    $m_name = $row['moviename'];
    $m_id = $row['movie_id'];
    echo "<a href='reservations.php?id=$m_id'>$m_name</a><br>";
    }
    [\code]


    This will produce a page like you described above. The second page will receive a movie id number from the link and you can then take that and look up the reservations for the id and do something similar to the above using reservations data instead of movie data.

    PS - I may have syntax error or something like that in the above, but you have a pretty good example to follow as you write your php code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles