-
Posts
442 -
Joined
-
Last visited
Everything posted by I-AM-OBODO
-
Hi all. my pagination does not show the info on next page? believe the problem is that the value of my $_GET[id] is not parse to the next page. but i dont know how to solve it. the error is unidentified id thanks my code $agent= $_GET['id']; $stmt = $pdo->prepare("SELECT surname, firstname FROM confirmed WHERE username = '$agent'"); $stmt->execute(); $row = $stmt->fetch(PDO::FETCH_ASSOC); $_SESSION['ref_agent'] = $row['surname'] . " ". $row['firstname']; error_reporting(E_ALL & ~E_NOTICE); /* Place code to connect to your DB here. */ // include your code to connect to DB. $tbl_name="processed"; //your table name // How many adjacent pages should be shown on each side? $adjacents = 5; /* First get total number of rows in data table. If you have a WHERE clause in your query, make sure you mirror it here. */ $stmt = $pdo->prepare("SELECT COUNT(*) as num FROM $tbl_name WHERE invitee = '$agent'"); $stmt->execute(); $total_pages = $stmt->fetch(PDO::FETCH_ASSOC); $total_pages = $total_pages['num']; /* Setup vars for query. */ $targetpage = "view-commission.php"; //your file name (the name of this file) $limit = 3; //how many items to show per page $page = $_GET['page']; if($page) $start = ($page - 1) * $limit; //first item to display on this page else $start = 0; //if no page var is given, set start to 0 /* Get data. */ $stmt = $pdo->prepare("SELECT * FROM $tbl_name WHERE invitee = '$agent' ORDER BY date_processed DESC LIMIT $start, $limit"); $stmt->execute(); //$num_rows = $stmt->rowCount(); //print "<p>$num_rows Record(s) Found.</p>"; /* Setup page vars for display. */ if ($page == 0) $page = 1; //if no page var is given, default to 1. $prev = $page - 1; //previous page is page - 1 $next = $page + 1; //next page is page + 1 $lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* Now we apply our rules and draw the pagination object. We're actually saving the code to a variable in case we want to draw it more than once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">« previous</a>"; else $pagination.= "<span class=\"disabled\">« previous</span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { for ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if($page < 1 + ($adjacents * 2)) { for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide some front and some back elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "..."; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close to end; only hide early pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next »</a>"; else $pagination.= "<span class=\"disabled\">next »</span>"; $pagination.= "</div>\n"; } echo "<table width='100%' class='table table-striped'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'> one</th> <th bgcolor='#444444' align='center'><font color='#fff'> two</font></th> <th bgcolor='#444444' align='center'><font color='#fff'> three</font></th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['trans_ref']; echo "</td><td>"; echo ucwords($row['payee']); echo "</td><td>"; echo number_format($row['amount'],2); echo "</tr></td>"; } echo "</table>"; <?php echo $pagination ?> thanks
-
Hi all. I have two tables where the username is what they have in common. i want to perform a join for both tables but i'm having problems with mysql joins. //to get the desire result individually i did //table one $stmt = $pdo->query("SELECT * FROM tableone WHERE username = '$_GET[id]'"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $credit_score = $row['credit_score']; $acct_num = $row['acct_num']; $acct_name = ucwords($row['surname']) ." ". ucwords($row['firstname']); $username = $row['username']; if($credit_score ==3){ $bill_limits = 2000; }elseif($credit_score ==2){ $bill_limits = 1000; }elseif($credit_score ==1){ $bill_limits = 500; } //table two $stmt=$pdo->query("SELECT SUM(amt) as bill FROM tabletwo WHERE username = '$_GET[id]' AND relationship = 'PARENT'"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $bill = $row['bill']; $service_charge_for_limits = '0.05' * $bill; $tax_rate_for_limits = '0.13' * $service_charge_for_limits; $bill_sum = $tax_rate_for_limits + $service_charge_for_limits + $bill; Approved Bill Limits = $<?php echo number_format($bill_limits,2); ?> <br> Bill Limits Used = $<?php echo number_format($bill_sum,2); ?> <br> <?php $available_limits = $bill_limits - $bill_sum; ?> Bill Limits Available = $<?php echo number_format($available_limits,2); ?> The above gives me the correct result, but now i have another page where i want to all the clients and their corresponding available limits, used limits and approve limits form table two and other information from table one On the page i have $stmt = $pdo->prepare("SELECT * FROM tableone WHERE status = 'COMPLETED' ORDER BY id DESC LIMIT $start, $limit"); $stmt->execute(); $num_rows = $stmt->rowCount(); echo "<table width='100%' class='table-responsive table-hover table-condensed table-striped'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'>Account Number</th> <th bgcolor='#444444' align='center'><font color='#fff'>Subscriber's Name</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Username</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Limits ($)</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>View Profile</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</font></th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['acct_num']; echo "</td><td>"; echo ucwords($row['surname']." ". $row['firstname']); echo "</td><td>"; echo $row['username']; echo "</td><td>"; $credit_score = $row['credit_score']; if($credit_score ==3){ $bill_limits = 2000; }elseif($credit_score ==2){ $bill_limits = 1000; }elseif($credit_score ==1){ $bill_limits = 500; } echo number_format($bill_limits, 2); echo "</td><td>"; echo "<a href='view-client-profile.php?id={$row['username']}'>view more</a>"; echo "</td><td>"; echo "<a href='delete-account.php?id={$row['username']}'>Delete Account</a>"; echo "</td></tr>"; //echo "</td><td>"; //echo "<a href='settle.php?id={$row['acct_num']}'>Points</a>"; } echo "</table>"; How ca i join tableone and tabletwo (plus sum)
-
yeah. u are right. the only relationship with both tables is the username. a table may have more info on it than the other. thanks
-
Hello all. I am trying to get values from two tables but i am getting the wrong output regardless of the type of join i use. The two query have some similar columns/rows. I want to fetch only the specified columns/rows with their unique data but my query is giving me on a column the value of just another column. For instance if a description column in table A has a value of INVOICE and on table B the description is RECEIPT all my query show is either INVOICE or RECEIPT in all the columns regardless of whether the description is receipt or not and also i want all the fields that is not on the other table to be blank and not replicate columns eg. description. image refuse to show when attached and wouldn't allow me to use the image link on the editor, said i am not allowed. SELECT table1.trans_ref, table1.description, table1.date_paid, table1.recurring, table1.amt, table1.bill_code, table2.trans_ref, table2.description, table2.amt_deposited, table2.deposit_date FROM table1 RIGHT JOIN table2 ON table1.username = table2.username ps: would want amount and deposit amount to be on same column and also use a where username = username. or maybe i am not doing the right thing? is it possible to a select on two tables without using a JOIN? so that you can echo only the needed values in a loop. thanks
-
Hi all. how can I use the results from my database query as a list items for a news ticker? thanks my code: $stmt = $pdo->query("SELECT * FROM ca_updates ORDER BY date DESC"); while($row = $stmt->fetch (PDO::FETCH_ASSOC)) { echo '<div id="example">'; echo '<ul>'; echo '<li>'; echo "<div class='update- heading'>"; echo "<h4><u>" . ucwords ($row['heading']) . "</u></h4>"; echo "</div>"; echo "<div class='update- date'>" . $row['date'] . '</ div>'; echo "<p class='update- contents'>" . $row ['contents'] . "</p>"; echo "</li>"; echo "</ul> echo "</div>
-
how can it b done with my login code? that's d issue
-
The code is my login page. currently only the user is able to login from there, but was wondering if i could modify it so that an admin can login into any of the account with a master password
-
Hi all, I am wondering how to get this to work or if it is possible. I have an application that was not built with the admin having access to all the users account but now i want it to have access to all accounts. Thanks. (though i've not tried anything yet, just dont know how to start and i dont want to start afresh: advice) My current login code is: <?php if(isset($_POST['login'])){ $username = stripslashes($_POST['username']); $password = stripslashes($_POST['password']); $stmt = $pdo->prepare("SELECT password FROM tablename WHERE username=:username"); $stmt->bindValue(':username', $username, PDO::PARAM_STR); $stmt->execute(); if($stmt->rowCount()<1){ echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD</div></p>'; }else{ list($hash) = $stmt->fetch(PDO::FETCH_NUM); if (password_verify($password, $hash)) { //$_SESSION['username'] = $username; $status1 = "COMPLETED"; $status2 = "PROCESSING"; //$stmt = $pdo->query("SELECT status FROM ca_confirmed WHERE username ='$_SESSION[username]'"); $stmt = $pdo->query("SELECT status FROM tablename WHERE username ='$username'"); $check = $stmt->fetch(PDO::FETCH_ASSOC); $status = $check['status']; $_SESSION['username'] = $username; if(strcmp($status, $status1) == 0){ header("location: completed/index.php"); exit(); }elseif(strcmp($status, $status2) == 0){ header("location: uncompleted/index.php"); //exit(); } }else{ echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD again</div></p>'; } } } ?>
-
login into two different areas on one login form
I-AM-OBODO replied to I-AM-OBODO's topic in PHP Coding Help
Thanks -
Hi all. I'm trying to get user login into two different areas on one login form based on a criteria. The problem I'm having is that if the correct passwords are provided, everything works fine but when a wrong password is provided, nothing happens, it doesn't even echo the password error alert! What could be wrong and is my code okay? Thanks if(isset($_POST['login'])){ $username=$_POST['username']; $password=$_POST['password']; $username = stripslashes($username); $password = stripslashes($password); $username = $username; $password = $password; //$pass = md5($password); $stmt = $pdo->prepare("SELECT password FROM table WHERE username=:username"); $stmt->bindValue(':username', $username, PDO::PARAM_STR); $stmt->execute(); if($stmt->rowCount()<1){ echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD</div></p>'; }else{ $password = $_POST['password']; list($hash) = $stmt->fetch(PDO::FETCH_NUM); if (password_verify($password, $hash)) { $_SESSION['username'] = $username; $status1 = "COMPLETED"; $status2 = "UNCOMPLETED"; $stmt = $pdo->query("SELECT status FROM table WHERE username ='$_SESSION[username]'"); $check = $stmt->fetch(PDO::FETCH_ASSOC); $status = $check['status']; if(strcmp($status, $status1) == 0){ header("location: completed/index.php"); exit(); }elseif(strcmp($status, $status2) == 0){ header("location: uncompleted/index.php"); exit(); }else{ echo '<div class="signals"><p class="bg-warning text-center warning"><button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>INVALID USERNAME OR PASSWORD again</div></p>'; } } } }
-
Finally this is what worked for me. I've tested it several times and it worked. mac_gyver was right but in my own case only the admin visits the site and not multiple users. Had to device my own means. Thanks mac_gyver and cronix for the inspiration!!! $stmt = $pdo->query("SELECT * FROM $tbl_name"); $stmt->execute(); $num_rows = $stmt->rowCount(); print "<p>$num_rows Record(s) Found.</p>"; echo "<table width='100%' border='1' bordercolor='#0cc' cellspacing='0' cellpadding='2'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'>Surname</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Firstname</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Email / Username</th> <th bgcolor='#444444' align='center'><font color='#fff'>Phone</th> <th bgcolor='#444444' align='center'><font color='#fff'>Date Registered</th> <th bgcolor='#444444' align='center'><font color='#fff'>Status</th> <th bgcolor='#444444' align='center'><font color='#fff'>Create Account</th> <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $clas = $row['entry']; if($clas == 'NEW'){ $style = " style='font-weight:bold'"; }else{ $style = " style='font-weight:normal'"; } // Print out the contents of each row into a table echo "<tr{$style}><td>"; echo ucfirst($row['surname']); echo "</td><td>"; echo ucfirst($row['firstname']); echo "</td><td>"; echo $row['email']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['today']; echo "</td><td>"; echo $row['status']; echo "</td><td>"; echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>"; echo "</td><td>"; echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>"; echo "</td></tr>"; } echo "</table>";
-
On the css rule, i just used that as an example but on the actually page i used a i did not use an in-line styling. I do not know how else to get it done, but this seem to work for me. Since i do not have an alternative, guess i'll stick with what i have and what i did was once the link is clicked, it updates the 'NEW' to 'OLD' thereby allowing only the clicked link to appear as normal text and not-clicked link always appear bold regardless of the number of views. Once it's not clicked it stays bold forever. I've tested it so many times and it didnt work-short of what i wanted. What's left is the notification stuff., Thanks
-
I have been able to solved one aspect of my question which is making the new entry bold. I just devised my own means of doing it, hope it works fine though. What's left is the notification. Will try to find a way around it and post. thanks
-
OOps! seems i kinda derailed a little. What i wanted doing is aside from having a notification, on the table the new entries should be bold while old entries should be normal text. thanks
-
Hello I ended up with my own idea. On the form, i create a hidden field as new_entry and on my table as well. So when the entry is clicked, i update the new_entry to old_entry. I created a css to make the new entry font-weight as bold and old entry font weight as normal. but the problem now is assigning the entries to my while condition, i.e if entry == old_entry the class = bold else class = normal my code $stmt = $pdo->query("SELECT * FROM $tbl_name"); $stmt->execute(); $num_rows = $stmt->rowCount(); print "<p>$num_rows Record(s) Found.</p>"; echo "<table width='100%' border='1' bordercolor='#0cc' cellspacing='0' cellpadding='2'>"; echo "<tr> <th bgcolor='#444444' align='center'><font color='#fff'>Surname</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Firstname</font></th> <th bgcolor='#444444' align='center'><font color='#fff'>Email / Username</th> <th bgcolor='#444444' align='center'><font color='#fff'>Phone</th> <th bgcolor='#444444' align='center'><font color='#fff'>Date Registered</th> <th bgcolor='#444444' align='center'><font color='#fff'>Status</th> <th bgcolor='#444444' align='center'><font color='#fff'>Create Account</th> <th bgcolor='#444444' align='center'><font color='#fff'>Delete Account</th> </tr>"; // keeps getting the next row until there are no more to get while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $clas = $row['entry']; if($clas == 'NEW'){ $style = "<div style='font-weight:bold'></div>"; }else{ $style = "<div style='font-weight:normal'></div>"; } // Print out the contents of each row into a table echo "<tr><td>"; echo ucfirst($row['surname']); echo "</td><td>"; echo ucfirst($row['firstname']); echo "</td><td>"; echo $row['email']; echo "</td><td>"; echo $row['phone']; echo "</td><td>"; echo $row['today']; echo "</td><td>"; echo $row['status']; echo "</td><td>"; echo "<a href='create-account.php?id={$row['id']}'>Create Account</a>"; echo "</td><td>"; echo "<a href='account-delete.php?id={$row['email']}'>Delete Account</a>"; echo "</td></tr>"; } echo "</table>"; how do i assign it to suit my need. Thanks
-
I tried to get the last id but its giving me error $stmt = $pdo->prepare("SELECT * FROM $tbl_name "); $stmt->execute(); $num_rows = $stmt->rowCount(); echo $num_rows Record(s) Found.; $last_id = $stmt->lastInsertId(); echo $last_id; but its giving this error: Fatal error: Call to undefined method PDOStatement::lastInsertId() it seems the lastInsertId() can only be used on an insert statement?
-
can u gimme an example on how to get the last displayed id?
-
Hello guys. Thanks. the issue have been resolved. The problem is from godaddy.
-
Hi all. Just seeing this error now. funny enough the site have been live for about a week only to bring this error now! Fatal error: Class 'PDO' not found in /home/mysite/public_html/includes/file.php on line 21 and this is the file.php $database='mydb'; $user='username'; $password='password'; $dsn="mysql:host=localhost;dbname=$database"; try { $pdo = new PDO($dsn,$user,$password); // mysql } catch(PDOException $e) { die ('Failed to connect'); // Exit, displaying an error message } i just saw this today and it's on godaddy thanks
-
hmmm. thanks. but how can one query for new notification thats the issue. doing a select alone can't get the new notification. my idea is you have to have a last count and any other entry that follows will be deemed as new. but the problem is I can't codify it.
-
hi all, how can i create a notification badge in php eg like when i have a new message, it will display on the nav indicating new message and the number of messages. thanks
-
Thanks. Will give it a shot
-
I have a referal system. I want to have a reward for referring someone. I allocate a certain amount for the referal system (lets say $50). At level 1, nothing is given until you start referring people and the person(s) starts using the program. On level 2 you earn 9%($4.5 of $50) on level 3 you earn 27% On level 4 you earn 64% How do i go about this bearing in mind that a level 2 or 3, eventually becomes level 1 if he starts inviting people and those he invited starts using the program. Thanks
-
sorry. my mistake. what I mean is for level 2 the parent receives 9% of 50 and level 3, he receives 27% and 64% for level 4. And so also will a referrer that have become a parent receive.
-
Assuming I set aside £50 for refering some one Level 1 will have nothing (since you are level 1) Level 2 will have £4.5 (9% of £50) Level 3 will have £13.50 (27% of £50) Level 4 will have £32 (64% £50)