Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: add a check or cross in mysql db

  1. #11
    Join Date
    Jan 2015
    Posts
    78
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default

    $row[35]
    Is that the correct column, and how do you know it is? Why aren't you using an associative or object fetch mode so that you would know that it is the correct column, regardless of what your query is SELECTing or how your table columns are organized?

    'Yes'
    Is that the correct value, with that exact capitalization?

  2. #12
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I counted the rows in phpmyadmin and is row 35 and the correct column, I am guessing it would be better to alter the following line

    FROM
    Code:
    $row = $result->fetch_row();
    TO

    Code:
    while ($row = $result->fetch_object())
    {
    then echo each row like the following method instead of $row[35] and so on

    Code:
    echo "<td><img src='images/" . (($row->indexed == 'Yes') ? 'green-check.png' : 'red-cross.png') . "' style='width: 30px; height: 30px;'></td>";
    I can confirm the 'Yes' is correct in the mysql with the capitalization

  3. #13
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    This is the error I am getting, it says on line 124 when I put error reporting in

    Notice: Undefined offset: 35 in

    Notice: Undefined offset: 35 in

    Notice: Undefined offset: 35 in

    Notice: Undefined offset: 35 in

    line 124 is below

    Code:
    echo "<td><img src='images/" . (($row[35] == 'Yes') ? 'green-check.png' : 'red-cross.png') . "' style='width: 30px; height: 30px;'></td>";

  4. #14
    Join Date
    Jan 2015
    Posts
    78
    Thanks
    0
    Thanked 19 Times in 19 Posts

    Default

    That's because it's not 35. Numerical array indexing starts at zero, which is why your code using $row[0] for the website_id works.

  5. #15
    Join Date
    May 2012
    Posts
    217
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Sorry have sorted the issue and made the coding easier and simpler and gone against how it was with $row[35] etc, I have done it like the following

    Code:
    <?php
    // connect to the database
    include('dbfile.php');
    
    $per_page=5;
    if (isset($_GET["page"])) {
    
    $page = $_GET["page"];
    
    }
    
    else {
    
    $page=1;
    
    }
    
    // Page will start from 0 and Multiple by Per Page
    $start_from = ($page-1) * $per_page;
    
    //Selecting the data from table but with limit
    $query = "SELECT removed column names FROM websites ORDER BY website_id LIMIT $start_from, $per_page";
    $result = mysqli_query ($mysqli, $query);
    
    //Now select all from table
    $query = "select * from websites";
    $result = mysqli_query($mysqli, $query);
    
    // Count the total records
    $total_records = mysqli_num_rows($result);
    
    //Using ceil function to divide the total records on per page
    $total_pages = ceil($total_records / $per_page);
    
    //Going to first page
    echo "<center><a href='../home.php'>Back to Main Dashboard</a> | <a href='view-all-websites.php'>View All Websites</a> | <a href='view-paginated-websites-data.php?page=1'>".'First Page'."</a> ";
    
    for ($i=1; $i<=$total_pages; $i++) {
    
    echo "<a href='view-paginated-websites-data.php?page=".$i."'>".$i."</a> ";
    };
    // Going to last page
    echo "<a href='view-paginated-websites-data.php?page=$total_pages'>".'Last Page'."</a></center> ";
    
    // display data in table
    echo "<table class='records'>";
    echo "<tr>
    <th>Website ID</th>
    <th>Category</th>
    <th>URL</th>
    <th>DA</th>
    <th>TF</th>
    <th>CT</th>
    <th>No Of Posts</th>
    <th>Last Post Date</th>
    <th>Indexed</th>
    <th colspan='2'>Actions</th>
    </tr>";
    
    while ($row = mysqli_fetch_assoc($result)) {
    // echo out the contents of each row into a table
    echo "<tr>";
    echo "<td><a href='view-specific-website-data.php?website_id=" . $row['website_id'] . "'>".$row['website_id'] . '</a></td>';
    echo "<td>" . $row['category'] . "</td>";
    echo "<td><a href='http://" . $row['url'] . "' target='_blank'>" . $row['url'] . "</a></td>";
    echo "<td>" . $row['da'] . "</td>";
    echo "<td>" . $row['tf'] . "</td>";
    echo "<td>" . $row['ct'] . "</td>";
    echo "<td>" . $row['no_of_posts'] . "</td>";
    echo "<td>" . $row['last_post_date'] . "</td>";
    echo "<td><img src='images/" . (($row['indexed'] == 'Yes') ? 'green-check.png' : 'red-cross.png') . "' style='width: 30px; height: 30px;'></td>";
    
    echo "<td><a href='add-update-website-data.php?website_id=" . $row['website_id'] . "'>Edit</a></td>";
    echo "<td><a href='delete.php?website_id=" . $row['website_id']. "'>Delete</a></td>";
    
    echo "</tr>";
    }
    
    // close table>
    echo "</table>";
    
    // close database connection
    $mysqli->close();
    
    ?>
    is working perfect now

Similar Threads

  1. Replies: 0
    Last Post: 01-04-2011, 01:17 PM
  2. Replies: 1
    Last Post: 10-20-2010, 06:18 AM
  3. Replies: 1
    Last Post: 12-27-2009, 01:12 AM
  4. Replies: 0
    Last Post: 03-07-2009, 07:27 PM
  5. Replies: 3
    Last Post: 01-08-2008, 12:49 PM

Bookmarks

Posting Permissions

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