dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: Database display

  1. #1
    Join Date
    Oct 2015
    Posts
    85

    Database display

    Hell guys i am coding a web site for ads , and now i am taking a part where i have to display my database records to my webpage , so this is my database Untitled-1_zps868nhoxh.jpg now there is only 2 rows as a sample but later will by much more like 100-1000 so now i need to display them on the web page like picture , title and something and other information i have diferent table for picture to save so this is just an information about ad , and i need an idea how should i do so i dont need a codes or something just asking you guys an idea how to do so ?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,115
    In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
    PHP Code:
    $queryResult $db->execute($your_sql_statement);
    while(
    $row $queryResult->fetch()) {
       echo 
    "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>\n";

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

  3. #3
    Join Date
    Oct 2015
    Posts
    85
    Quote Originally Posted by NogDog View Post
    In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
    PHP Code:
    $queryResult $db->execute($your_sql_statement);
    while(
    $row $queryResult->fetch()) {
       echo 
    "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>\n";

    okay that was good for me i think to do it with for loop but did you way , but the thing i want is something like this :

    un_zpsfapp8wvd.jpg

    and i get only like text from data base , i am not very familiar with php styling but i do not think that i can do it with only php so now question is how to include a html into a php code cuz now i have a simple code :
    <?php

    $userid = $_SESSION["userid"];
    $sql = "SELECT * FROM posts WHERE userid='$userid' ";
    $res = mysqli_query($connect,$sql);
    $rowcount = mysqli_num_rows($res);
    while ($row = mysqli_fetch_assoc($res)) {
    echo "<p>".$row["title"]."\n".$MainPhoto."</p>\n";
    }

    ?>
    with no style at all

  4. #4
    Join Date
    Oct 2015
    Posts
    85
    Quote Originally Posted by NogDog View Post
    In PHP it's probably most commonly done via a while() loop on a DB query result set. E.g.:
    PHP Code:
    $queryResult $db->execute($your_sql_statement);
    while(
    $row $queryResult->fetch()) {
       echo 
    "<p>{$row['col_1']} <i>{$row['col_2']}</i></p>\n";

    okay that was good for me i think to do it with for loop but did you way ,but now i have a problem i have tables (images,posts)
    posts is for all information and images are for a image of the post (for path) so now have the question how to select and use both of those tables hare is my code for now :
    <?php

    $userid = $_SESSION["userid"];
    $sql = "SELECT * FROM posts WHERE userid='$userid' ";
    $res = mysqli_query($connect,$sql);
    while ($row = mysqli_fetch_assoc($res)) {
    ?>
    <p class="ads" >
    <a href=""><?php echo $row["title"]; ?></a><br>
    <a href=""><img src=""></a>
    </p>
    <?php
    }

    ?>

  5. #5
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    1,488
    You need to learn some html, some CSS and how to code. We are here to HELP you when you attempt that, but we are NOT here to write your code for you. So - make the effort and post what you have problems with and THEN we can help you out. If you just want someone to do your work, there is another forum of 'for hire' people.
    JG
    PS - If you're posting here you should be using:

    error_reporting(E_ALL);
    ini_set('display_errors', '1');


    at the top of ALL php code while you develop it!

  6. #6
    Join Date
    Oct 2015
    Posts
    85
    Dont need anything solved by joining a tables and use $row to extract data :

    <?php

    $userid = $_SESSION["userid"];
    $sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE userid='$userid' ";
    $res = mysqli_query($connect,$sql);
    while ($row = mysqli_fetch_assoc($res)) {
    ?>
    <div id="ads">
    <div id="titlepic">
    <a href=""><?php echo $row["title"]; ?></a><br>
    <a href=""><img src="<?php echo $row["path1"]; ?>" height="100px" width="150px"></a>
    </div>
    <div id="managead">
    <a href="">Edit</a><br style="margin-bottom: 5px;">
    <a href="">Delete</a><br style="margin-bottom: 5px;">
    <a href="">Renew</a>
    </div>
    <div id="dates">
    <b>Date Added:</b> <?php echo date('m/d/Y', $row["dateadded"]); ?><br>
    <b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y', $row["renewdate"]); } ?><br>
    <b>Location:</b> <?php echo $row["location"]; ?><br>
    <b>Price:</b> <?php echo $row["price"]; ?><br>
    </div>
    </div>
    <hr width="100%">
    <?php

  7. #7
    Join Date
    Oct 2015
    Posts
    85
    Have a new problem with a javascript :
    Top:
    PHP Code:
    if (isset($_GET['delete'])){
        
    $postid $_GET["id"];
        
    $sql "DELETE p,i FROM posts p JOIN images i ON p.id = i.postid WHERE postid='$postid' ";
        
    $res mysqli_query($connect,$sql);

    script :
    HTML Code:
    <script>
    function myFunction() {
        var txt;
        var r = confirm("Are you sure you want to delete ?");
        if (r == true) {
            window.location.href = 'ads.php?delete=true&id=<?php echo $row["postid"]; ?>';
        } else {
            
        }
    }
    </script>
    and main code :
    PHP Code:
                    <?php

                        $userid 
    $_SESSION["userid"];
                        
    $sql "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE userid='$userid' ";
                        
    $res mysqli_query($connect,$sql);
                         while (
    $row mysqli_fetch_assoc($res)) {
                             
    ?>
                            <div id="ads">
                                <div id="titlepic">
                                <a href=""><?php echo $row["title"]; ?></a><br>
                                <a href=""><img src="<?php echo $row["path1"]; ?>" height="100px" width="150px"></a>
                                </div>
                                <div id="managead">
                                <a href="ads.php?edit=true&id=<?php echo $row["postid"]; ?>" >Edit</a><br style="margin-bottom: 5px;">
                                <a href="ads.php?delete=true&id=<?php echo $row["postid"]; ?>" onclick="myFunction()" >Delete</a><br style="margin-bottom: 5px;">
                                <a href="ads.php?renew=true&id=<?php echo $row["postid"]; ?>">Renew</a>
                                </div>
                                <div id="dates">
                                    <b>Date Added:</b> <?php echo date('m/d/Y H:i'$row["dateadded"]); ?><br>
                                    <b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y H:i'$row["renewdate"]); } ?><br>
                                    <b>Location:</b> <?php echo $row["location"]; ?><br>
                                    <b>Price:</b> <?php echo $row["price"]."&pound"?><br>
                                    
                                </div>
                            </div>
                            <hr width="100%">
                            <?php
    so the problem is no meter what i press ok or cancel the ad will by deleted anyway ,so i need to edit a javascript somehow to get the result only if it ok
    Last edited by NogDog; 05-11-2016 at 09:58 AM. Reason: changed [quote] tags to [php] or [html] tags

  8. #8
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    21,115
    <MOD>Please note the changes I made to the preceding post, replacing the [quote] tags with applicable [php] and [html] tags. Help us help you, by using the force ... I mean forum ... wisely.</MOD>

    http://www.webdeveloper.com/forum/misc.php?do=bbcode (bbcode tags)
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

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