Jump to content
Stef's Coding Community

Basic PHP System: View, Edit, Add, Delete records with MySQLi


Recommended Posts

  • Replies 96
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Check out our new Interactive Web Developer course (created in 2016) that covers this, and much more: shop.killervideostore.com   This is a revised version of my previous tutorial (http://www.killer

the $row[0] is a variable that holds the id of the record, creating a url that includes the id, like this: "records.php?id=12". On the records page, you can use $_GET[] to get the id and know which re

Great coding! When/if you do another revision, here is the project I made that uses Ajax instead of a hidden form and uses id's for each row in the html instead of an href link. Lastly, my version all

Posted Images

  • 11 months later...

My dear friend Falken,

I just registered to the forum to ask you a question. 

Is there any chance tonight or tomorrow you will update your PHP Pagination Tutorial so Ajax, jQuery and Prepared Statements are used ? 

That way, whole pages won't need reloading to update data on our pagination pages. Plus we get SQL injection proof added. 

I am a PHP Student. Still on procedural style and Mysqli and prepared statements. Haven't got into pdo or Oop style or JavaScript or any other programming language yet. 

Also your pagination contains the page number links at the top of the page. Would be great if there were a copy on the bottom of the page too.

Also can you update it to make it Mobile Responsive for all devices ? Don't bother revolving around Twitter's bootstrap as better not to be dependant on a commercial company's template.

Do drop me a PM after you've updated your tutorial to 2019 standard.

 

PS - May we see a PHP Mysqli & Prepared Statement tutorial from you on Member Registration & Login site ? 

And another tutorial where you teach us how to build a search chengine (Search feature, Crawler, Index, etc) with mysqli and prepared statements and Ajax and jQuery ?

Thank You!

Edited by LiverSite
Link to post
Share on other sites
  • 3 weeks later...

I am using this script and all works fine but is it possible to add a active class to the pagination so when on page 6 for example, the number 6 is highlighted so know which page number I am on, below is the current code I have

// 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 "<div class='btn-group' style='margin:0 auto;display:table;'>";
echo "<br><br><center><a href='view-all-customers.php?page=1' class='btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".'First Page'."</a>";

for ($i=1; $i<=$total_pages; $i++) {

echo "<a href='view-all-customers.php?page=".$i."' class='btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".$i."</a>";
};
// Going to last page
echo "<a href='view-all-customers.php?page=$total_pages' class='btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".'Last Page'."</a></center>";
echo "</div>";

UPDATE: I managed to get it working using the following coding

//check page and add active class

for ($i=1; $i<=$total_pages; $i++) {
    $isActive = '';
    if($i == $page){
        $isActive = 'active';
    }

    echo "<a href='view-all-customers.php?page=".$i."' class='".$isActive."btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".$i."</a>";
};

The complete code is below if anyone else needs it

// 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 "<div class='btn-group' style='margin:0 auto;display:table;'>";
echo "<br><br><center><a href='view-all-customers.php?page=1' class='btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".'First Page'."</a>";

//check page and add active class

for ($i=1; $i<=$total_pages; $i++) {
    $isActive = '';
    if($i == $page){
        $isActive = 'btn-active';
    }

echo "<a href='view-all-customers.php?page=".$i."' class='".$isActive." btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".$i."</a>";
};
// Going to last page
echo "<a href='view-all-customers.php?page=$total_pages' class='btn btn-primary float-button-light' style='color:#FFFFFF;padding:6px 15px;'>".'Last Page'."</a></center>";
echo "</div>";

 

Edited by ianhaney
solved the issue
Link to post
Share on other sites
  • 1 year later...

Insert SQL statements
INSERT INTO Books(Id, Title, Author) VALUES(1, 'War and Peace', 
    -> 'Leo Tolstoy');

Replace SQL statements
REPLACE INTO Books VALUES(3, 'Paradise Lost', 'John Milton');
Query OK, 2 rows affected (0.00 sec)

Delete SQL statements
DELETE FROM Books2;

Update SQL statements
UPDATE Books SET Author='Lev Nikolayevich Tolstoy'
    -> WHERE Id=1;

 

These are basic sql statement for inert, replace, delete and update your sql table.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...