Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Page 1 of 2 1 2 LastLast
Results 1 to 10 of 17
  1. #1
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    I am trying to use php within a div tag which will then be repeated. The problem is that there is HTML code between the php code. I have included what I have done so far. If you want a visual example of what I am trying to do check out http://www.mediareviewzone.com I want the small description boxes to be able to be populated from a database. The code below is supposed to enter the title, links, description, and an image into the description box as it appears now on the site. I want it then to repeat until all the descriptions have been placed on the page. My errors start at the <div class="par_element2"> line due to the fact that it is HTML inside php code. Any help would be appricated.

    <div class="par_element">
    <?php $subject_set = mysql_query("Select FROM * movies", $connection);
    if (!$subject_set){
    die("Database connection failed: " . mysql_error());
    }
    while ($subject = mysql_fetch_array($subject_set)){
    <div class="par_element2">
    <h2> echo {$subject["link"]};echo {$subject["title"]};</a></h2>
    echo {$subject["description"]}; echo {$subject["link"]}; read more on echo {$subject ["title"]};.</a></div>
    echo {$subject["link"]};<img src= echo {$subject["picture"]}; alt=echo {$subject["title"]}; name=echo {$subject["title"]}; width="65" height="100" border="0" id=echo {$subject["title"]}; /></a>
    }?>
    </div>
    </div>
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    This is the coolest thing about mixing HTML with PHP ...

    You can actually drop in and out, and yet retain the construction of the loops { ... }
    Note, I have to change how I comment, because some comments are PHP,
    and some are HTML comments.

    PHP Code:
    <!-- starting with HTML -->
    <div class="par_element">
    <?php
    // going into PHP now ...
    $subject_set mysql_query("Select FROM * movies"$connection);
    if (!
    $subject_set){
    die(
    "Database connection failed: " mysql_error());
    }
    while (
    $subject mysql_fetch_array($subject_set)){
    // now we drop out of PHP, but we're still in the loop
    ?>
    <!-- this part is HTML with PHP variables embedded in it -->
    <div class="par_element2">
    <h2><a href="<?=$subject['link']?>"><?=$subject['title']?></a></h2>
    <?=$subject['description']?>
    <a href="<?=$subject['link']?>">read more on <?=$subject['title']?></a></div>
    <a href="<?=$subject['link']?>"><img src="<?=$subject['picture']?>" alt="<?=$subject['title']?>" name="<?=$subject['title']?>" width="65" height="100" border="0" id="<?=$subject['title']?>" /></a>
    <?php
    // back into PHP to pick-up the closing bracket of the while loop.
    // end of while loop
    ?>
    <!-- back into HTML again -->
    </div>
    </div>
    John Mc Grath likes this.


  4. #3
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    Thanks, that worked perfectly. There was a couple of small changes that had to be made which was to place one of the </div> before the close of the while loop and the * when defining the table had to be before FROM (just incase someone else is going to use this code). I also needed to place the par_element tag within the loop. The code works great but for some reason five of the elements are placed correctly but the rest are then placed side by side at the bottom of the page. My page probably just needs some modification. Thanks again for that code, you really saved me a lot of time. Probably would have taken me days or weeks to get it working.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  5. #4
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    I'm guessing your page has a fixed height and can only contain 5.
    Try running your code on a test page with no container restrictions.
    Let it expand vertically as much as it needs.

    Another thought ... add a condition to the SELECT so you only select
    perhaps 12 of the movies. Maybe select only the one's starting with
    a particular letter, or the title is "LIKE" a particular word.

    $search="warrior";
    $subject_set = mysql_query("Select FROM * movies WHERE title LIKE '%$search%' ", $connection);

    That would only result in movies with the word "warrior" in the title.
    MySQL is not case-sensitive by default, so don't worry about upper or lower case.
    John Mc Grath likes this.


  6. #5
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    I have auto height on the container. I removed the container and only three elements where placed right. I then removed the sidebar and still only three right but the others moved up but still side by side instead of under each other. It probably just needs some adjustments.

    I will be implementing the conditions when I have this working correctly. Any ideas how to feed conditions from one page to another. For example, if someone is viewing the warrior page and then they select action games out of the navigation menu, I want it to go to the games page and only show the action games. I am also going to create another table containing page titles which will also load when changing page. At the moment I have a page for each element in the navigation. I was hoping to use just one page to do all the genres. Thanks again for your help.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  7. #6
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    Of course ... it's one PHP script for ALL pages if you want it that way.
    Your database (the columns you have) will be the key factor. If you have a column
    for "genre", or a column for "movie rating", or a column for "whatever", you search
    and select by those columns.

    Here's a clue for you ... whatever the page parameters or type of movie the user wishes
    to see, when they select that, save it in a cookie. That user will only see what the cookie
    determines (until they change to something else) ... even if they leave and come back in a week.

    The layout problems ...
    Really tough to know the answer to that without seeing your website.

    Here's something I've been pondering ....
    If one of your sites is mediareviewzone.com, what is this thread about?
    It seems to me that you already have it done and working. Post #1 says that
    mediareviewzone is an example of what you're trying to do, but your "sig" says
    it's one of your sites. baffling.:unsure:
    John Mc Grath likes this.


  8. #7
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    mediareviewzone.com is my main site. I designed it using html and css only. Now I am teaching myself php and sql so I am trying to modify the site to make it better. As the site grows larger it will get very messy if I only use html.

    I made a bit of progress with the layout problem. I removed my main_content div and all the elements are in the right place vertically but they shift to the left of the screen out of the wrapper after the first four. I recon I will fix it soon enough with a few more changes.

    Concerning just using one page for genres, I kind of know how to organise the list on the page but what I am not sure of is how to populate the page if you navigate from another page. If I navigated to horror movies from the battlefield game page (which does not use a table) how do I only have horror movies and not all movies. Do I need to add php code to all the links in the navigation menu? Thanks again for your time.

    I only created my sig the other day and was wondering if it was alright. I can change it if there are any issues.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  9. #8
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    I fixed the layout problems, it was caused by some of the div tags floating to the left.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com

  10. #9
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    You have the genre in your links ....
    mediareviewzone.com/?g=horror

    The PHP script gets the value of the variable "g" and
    queries the database for only genres called "horror".

    If your link has an "s" variable, that would see it as a search keyword.
    mediareviewzone.com/?s=battlefield

    The search keyword could look at titles, descriptions, or whatever you want.

    Maybe you want to search for "guts" only in the "horror" genre?
    mediareviewzone.com/?g=horror&s=guts

    PHP can do anything you want. MySQL is really powerful too.
    How you structure and organize your MySQL table(s) is really important.

    And not only do you need to develop your site, but you'll need a whole admin
    section to add/edit/delete things in the database. You'll spend as much time
    creating the admin section as you will your site.
    John Mc Grath likes this.


  11. #10
    Member John Mc Grath's Avatar
    Join Date
    Sep 2011
    Location
    Ireland
    Posts
    80
    Member #
    29172
    Liked
    3 times
    I see what you mean, I think I see how I can implement it. One problem I am going to have with my current database design is that there are five genre columns because most movies are covered by more than one genre. So, from what you said above, should I enter all the genres into the one column and let the code pick out the word I am looking for? For example if under genre there was horror, comedy, drama and I searched for horror it could select that item because it had horror contained in the string.
    Im pretty new to web design but I am learning fast. I will help if I can.
    Check out my sites http://www.mediareviewzone.com http://www.iamrobsmith.com


Page 1 of 2 1 2 LastLast

Remove Ads

Posting Permissions

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

Search tags for this page

how to repeatedly add div to a html page using php loops
,

php repeat div

Click on a term to search for related topics.
All times are GMT -6. The time now is 12:43 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com