
Copilot π€
Members-
Posts
20 -
Joined
-
Last visited
Copilot π€'s Achievements

Newbie (1/5)
0
Reputation
-
naming properly the primary keys, how to concatenate
cary1234 replied to cary1234's topic in PHP Coding Help
Thanks I got the idea. Yeah you are right. Thank you very much- 7 replies
-
- proper naming
- primary keys
-
(and 3 more)
Tagged with:
-
naming properly the primary keys, how to concatenate
cary1234 replied to cary1234's topic in PHP Coding Help
Thanks Barand, yeah I already thought of that to make my life easier. But my client ask me before if it is possible to create some pattern in the id's. They wanted me to create id according to the batch+incrementing number. So that they can easily identify it, what batch is this person. Because in other company whenever a user creates a new account the id naming is year of birthdate + incrementing numbe (example: 199201, 1992 is birthdate and 01 is the incrementing number). What do you think? Is it possible? I'm thinking whether should I change the naming of id's...- 7 replies
-
- proper naming
- primary keys
-
(and 3 more)
Tagged with:
-
naming properly the primary keys, how to concatenate
cary1234 replied to cary1234's topic in PHP Coding Help
I tried to use AUTO_INCREMENT but it didn't worked out here's my code $final_u_ID = $batch . mysqli_insert_id($db_Connection) Whenever I register another user nothing happened maybe because of the same primary key. Do you have any idea on how do I concatenate and get the last 3 digits of my u_ID in database? Example: 52001 = I will concatenate it so it will become 52 / 001 then I will get the last 3 digits which is 001 then add +1 to that? Other Examples: 35001 then if another user register with the same batch number it will become 35002 Take note that the user has freedom on what batch they want. Thanks QuickOldCar- 7 replies
-
- proper naming
- primary keys
-
(and 3 more)
Tagged with:
-
I'm having a problem on how do I put primary keys whenever a user register another person. My pattern is this (batch number) + (incrementing value). For example a person named Cary register to my website and he inputted his batch number as batch 53, so his primary will become 53001. Then if another person named Josh with batch number 53 again register to my website his primary should be 53002. Then another person name Brock register but his batch is 36 so his primary should be 36001. So my solution is to get the batch number that the user inputted while they are registering then combine it with the incrementing value. My problem is how do I get the incrementing value and let the php know the next incrementing value? How do php know that the next number will be 003 or 004 or 005.
- 7 replies
-
- proper naming
- primary keys
-
(and 3 more)
Tagged with:
-
I got the code and explanation in this forum http://www.dreamincode.net/forums/topic/252413-how-to-remove-notice-undefined-index/
-
So far this is what I did to apply your code Barand <input type="checkbox" id="cb_Fname" name="cb_Fname" value="1">First Name</label> <input type="text" id="tb_Fname" name="tb_Fname"> <br /> <input type="checkbox" id="cb_Lname" name="cb_Lname" value="1">Last Name</label> <input type="text" id="tb_Lname" name="tb_Lname"> <br /> <?php require('/Functions/db_Connect.php'); $db_Connection = mysqli_connect($db_Host, $db_User, $db_Pass, $db_Name); $cb_Fname = $_POST['cb_Fname']; $tb_Fname = $_POST['tb_Fname']; $cb_Lname = $_POST['cb_Lname']; $tb_Lname = $_POST['tb_Lname']; $where = array(); $whereclause = ''; if (isset($tb_Fname) && !empty($tb_Fname)) { $where[] = "fname like '%$tb_Fname'"; } else { echo "mali ito A"; } if (isset($tb_Lname) && !empty($tb_Lname)) { $where[] = "lname like '%$tb_Lname'"; } else{ echo "mali ito B"; } // etc if (count($where) > 0) $whereclause = "WHERE " . join(' AND ', $where); $sql = "SELECT * FROM trainees $whereclause"; echo $sql; ?> But I dont know, I think what I'm doing is wrong or Im missing something
-
Thanks Barand for your reply, I tried to apply your code but honestly I dont know how to change. I have so many questions, like what should I put in col1, condition1, $whereclause, etc.. etc... also why is it that there are 2 columns now in $sql (foo, bar) Will you please explain it more? Thanks wittenberg for your reply, I dont know if there are any other way for this but my purpose is to give the user some choices on how to specifically search βwhat they want, what if there are 500 users that has a firstname 'Jack' but they lived in different place and what the user wants to search is 'Jack' that lives in 'netherland' only I'm sure if I give the user some options they will be happy. And also the purpose of checkbox is to limit the user not to type if the user didn't check the checkbox, this is to prevent them from accidentally typing. SORRY FOR MULTIPLE POST, THATS BECAUSE OF INTERNET CONNECTION ISSUES OF MINE
-
Hello! Right now I'm working on advance search for my website and I'm stuck on this part of my website. I'm glad I can shout for help here in you forums. What I want is whenever a user use the advance search the user can search for first name, last name, middle name and lastly nick name. The Condition: Sometimes the user may want to define their search specifically like for example I want to search all the people who have a last name "Bondoc" that lives in "Philippines" so they will check the checkbox for first name and country then click the advance search. What is the best code for this logic? Right now this is what I did.. But I guest I will code every type of combination which really needs some effort, any other idea please? INPUT THE RESULT And here's my code $db_Connection = mysqli_connect($db_Host, $db_User, $db_Pass, $db_Name); $cb_Fname = $_POST['cb_Fname']; $tb_Fname = $_POST['tb_Fname']; $cb_Lname = $_POST['cb_Lname']; $tb_Lname = $_POST['tb_Lname']; if ($cb_Fname == "1"){ //checkbox is CHECKED $fname = "fname LIKE '%$tb_Fname%'"; } else{ //checkbox not CHECKED $fname = ""; } if ($cb_Lname == "1"){ //checkbox is CHECKED $lname = "AND lname LIKE '%$tb_Lname%'"; } else{ //checkbox not CHECKED $lname = ""; } $qry_Ftt = mysqli_query($db_Connection, "SELECT * FROM users WHERE $fname $lname"); ?>
-
Thanks fastsol, okay. I will study those.
-
Greetings, as what the title says I want to add search function to my website that looks like facebook (even if you dont press ENTER the result can be seen already and it searches for every letter combination ex. if I type 123 the result would be cary1234) I already tried searching to search in google the results are as follows 1. http://www.9lessons.info/2009/06/autosuggestion-with-jquery-ajax-and-php.html I try to copy-paste the code, but they arent working. I also dont understand the code. 2. http://www.codeforest.net/simple-search-with-php-jquery-and-mysql This link is much better I think, it doesnt give me exact facebook searching but the codes has comments so I can understand. Problem is I'm stuck in this code. <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db.php'); $db = new db(); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysql_real_escape_string($_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT title, url FROM pages WHERE content LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?> I tried to fix the code but I'm failed, the error is Fatal Error: Call to undefined method::mysqli_select_list() in ....... line 14 <?php //if we got something through $_POST if (isset($_POST['search'])) { // here you would normally include some database connection include('db_Connect.php'); $db = mysqli_connect($db_Host, $db_User, $db_Pass, $db_Name); // never trust what user wrote! We must ALWAYS sanitize user input $word = mysqli_real_escape_string($db, $_POST['search']); $word = htmlentities($word); // build your search query to the database $sql = "SELECT fname FROM pages WHERE fname LIKE '%" . $word . "%' ORDER BY title LIMIT 10"; // get results $row = $db->select_list($sql); if(count($row)) { $end_result = ''; foreach($row as $r) { $result = $r['title']; // we will use this to bold the search word in result $bold = '<span class="found">' . $word . '</span>'; $end_result .= '<li>' . str_ireplace($word, $bold, $result) . '</li>'; } echo $end_result; } else { echo '<li>No results found</li>'; } } ?> I want to change it to mysqli, but I dont know. Please help.
-
Running MySQL Query with Union (2 SELECT) on PHP
cary1234 replied to cary1234's topic in PHP Coding Help
Now I know. I just make the code like this <?php $qry_attendanceLtm = ("SELECT COUNT(*) FROM (SELECT tbl_users.fname, tbl_users.lname, tbl_users.age, tbl_users.address, tbl_users.contact_Num, tbl_users.district_Num, tbl_dateofmeetings.date FROM tbl_dateofmeetings LEFT OUTER JOIN tbl_users ON tbl_users.user_ID=tbl_dateofmeetings.user_ID WHERE tbl_dateofmeetings.meeting_Code=1 AND tbl_dateofmeetings.district_Num=1 AND tbl_users.district_Num=1 UNION SELECT tbl_users.fname, tbl_users.lname, tbl_users.age, tbl_users.address, tbl_users.contact_Num, tbl_users.district_Num, tbl_dateofmeetings.date FROM tbl_dateofmeetings RIGHT OUTER JOIN tbl_users ON tbl_users.user_ID = tbl_dateofmeetings.user_ID WHERE tbl_dateofmeetings.meeting_Code=1 AND tbl_dateofmeetings.district_Num=1 AND tbl_users.district_Num=1) AS Result"); $temp_AttendanceLtm = mysqli_query($db_Connection, $qry_attendanceLtm); $temp1_AttendanceLtm = mysqli_fetch_assoc($temp_AttendanceLtm); $final_AttendanceLtm1 = $temp1_AttendanceLtm['COUNT(date)']; echo $final_AttendanceLtm1; ?> -
Running MySQL Query with Union (2 SELECT) on PHP
cary1234 replied to cary1234's topic in PHP Coding Help
Ahh. Thank you for your tips, yeah I think you are right I need to remove thos 'tbl_'. Hmmm. I have another problem sir. How can I put 'COUNT' if the query is like this. <?php $qry_attendanceLtm = ("SELECT tbl_users.fname, tbl_users.lname, tbl_users.age, tbl_users.address, tbl_users.contact_Num, tbl_users.district_Num, tbl_dateofmeetings.date FROM tbl_dateofmeetings LEFT OUTER JOIN tbl_users ON tbl_users.user_ID=tbl_dateofmeetings.user_ID WHERE tbl_dateofmeetings.meeting_Code=1 AND tbl_dateofmeetings.district_Num=1 AND tbl_users.district_Num=1 UNION SELECT tbl_users.fname, tbl_users.lname, tbl_users.age, tbl_users.address, tbl_users.contact_Num, tbl_users.district_Num, tbl_dateofmeetings.date FROM tbl_dateofmeetings RIGHT OUTER JOIN tbl_users ON tbl_users.user_ID = tbl_dateofmeetings.user_ID WHERE tbl_dateofmeetings.meeting_Code=1 AND tbl_dateofmeetings.district_Num=1 AND tbl_users.district_Num=1"); $temp_AttendanceLtm = mysqli_query($db_Connection, $qry_attendanceLtm); $temp1_AttendanceLtm = mysqli_fetch_assoc($temp_AttendanceLtm); $final_AttendanceLtm1 = $temp1_AttendanceLtm['COUNT(date)']; echo $final_AttendanceLtm1; ?> As you can see on the 2nd to the last line I have this "$final_AttendanceLtm1 = $temp1_AttendanceLtm['COUNT(date)'];" Because I put "COUNT" on that variable I also need to put "COUNT" on the query itself, but how? -
Running MySQL Query with Union (2 SELECT) on PHP
cary1234 replied to cary1234's topic in PHP Coding Help
Oh yes, it worked. Oh I'm sorry. I thought its a big problem because I already checked it for more thatn 5 times. Sorry and anyways, I really want to than you. -
Running MySQL Query with Union (2 SELECT) on PHP
cary1234 replied to cary1234's topic in PHP Coding Help
By the way I'm sure the query is working because I tested it on phpmyadmin -
Running MySQL Query with Union (2 SELECT) on PHP
cary1234 replied to cary1234's topic in PHP Coding Help
Yeah, thats my problem. I think that query doesnt need special handling but it didnt work. The error states that mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in ......