Posts

Showing posts with the label mysql

Sorting MySQL data into limit sized pages, and onscreen option to change pages? How is it done? [on hold]

Image
Sorting MySQL data into limit sized pages, and onscreen option to change pages? How is it done? [on hold] I am new to HTML and CSS, however I have some basic knowledge of programming games in C# and Java (using frameworks like LibGDX, Unity etc). I've built a database in MySQL and the corresponding php code that displays a html article for each entry in the table. Everything is working great but the whole database loads onto one big webpage. I have been reading around a lot but cannot seem to find where to start on building it into pages. The only idea I can imagine right now is that I will need a field somewhere on my site to hold the current page number the user selected, and then in my SQL SELECT statement use that figure to somehow pull only say 20 pages starting from 'currentPage * 20' for example. I've found small parts of the info I need like I see there may be a LIMIT clause I can use. But how can the SELECT * FROM table ORDER BY id DESC LIMIT (currentPage*20); ...

MySQL JOIN whether null or not

MySQL JOIN whether null or not I'm pretty out of practice with MySQL and PHP, but I have a project I'm working on for a friend that involves selecting data from two tables, and combining them into one result - seems simple. Table 1 has 13 fields, but the important ones are id (auto-increment, primary key) and serial (unique). The rest are just ones like customer , description , etc. etc. Pictures has 3 fields, picID (auto-increment, primary key), imagePath and serial I need to retrieve all data from Table 1, and if there is a matching photo (identified by the same serial - only ever 1 photo possible per serial) in Pictures, then retrieve that data too. I then output the data from Table1, and use imagePath from Pictures to build an image in HTML if one has been uploaded. The query I've been using is: $sql = "SELECT * FROM Table1 LEFT JOIN Pictures ON Table1.serial = Pictures.serial ORDER BY Table1.serial"; Which seems perfect, EXCEPT if any row from Table1...

SQL Query not updating the database

SQL Query not updating the database I was getting an error from my processing form down below. I'm not sure why it isn't updating to the database when I hit submit. It says it has been successful but yet the databse has not been updated?! I think it maybe because of the "mysqli_stmt_execute" but I'm not sure. Any thoughts :/ Thanks. <?php if(isset($_POST['submit'])){ include_once 'connection.php'; $first = mysqli_real_escape_string($conn, $_POST['first']); $last = mysqli_real_escape_string($conn, $_POST['last']); $uid = mysqli_real_escape_string($conn, $_POST['uid']); $pwd = mysqli_real_escape_string($conn, $_POST['pwd']); $hashedPwd = md5($pwd); //Error Handling //Checking for empty fields if(empty($first) || empty($last) || empty($uid) || empty($pwd)){ header("Location: ../signup.php?signup=empty"); exit(); }else{ //Checking if the input...

MySQL join together 2 columns without duplicates

MySQL join together 2 columns without duplicates I have a tablethat looks like following: username is_superuser last_login name roles roles_for_groups rob 0 21-06-18 CCTSAT dev full_access rob 0 21-06-18 CCTSAT ReadOnly ReadOnly rob 0 21-06-18 CCTSAT ReadOnly full_access rob 0 21-06-18 CCTSAT ReadOnly_Setup SampleReadOnly rob 0 21-06-18 CCTSAT ReadOnly_Setup full_access rob 0 21-06-18 CCTSAT full_access SampleReadOnly rob 0 21-06-18 CCTSAT full_accessCC full_accessCC rob 0 21-06-18 CCTSAT full_accessGLE SampleReadOnly rob 0 21-06-18 CCTSAT full_accessGLE full_accessCC rob 0 21-06-18 CCTSAT prod_full_access SampleReadOnly rob 0 21-06-18 C...

mysqli_real_escape_string doesn't seem to be working

mysqli_real_escape_string doesn't seem to be working I am a novice in PHP. I am trying to insert a variable's value into a MariaDB table and was trying to use mysqli_real_escape_string to escape '$value'. I got the idea from here. It inserted an empty string to the table(I did add a connection link to the database). So, I copied and pasted the following code from PHP Manual, it still didn't work. The output I got was an error code alone: Error: 42000. What am I missing? I am using a Virtualbox, OS: CentOS7 <?php $link = mysqli_connect("localhost", "my_user", "my_password", "world"); /* check connection */ if (mysqli_connect_errno()) { printf("Connect failed: %sn", mysqli_connect_error()); exit(); } mysqli_query($link, "CREATE TEMPORARY TABLE myCity LIKE City"); $city = "'s Hertogenbosch"; /* this query will fail, cause we didn't escape $city */ if (!mysqli_query($link, "I...

MySql function returns null everytime

MySql function returns null everytime I have the following function: (The SQL query works perfectly) CREATE FUNCTION get_participantes (pid INT) RETURNS varchar(255) DETERMINISTIC BEGIN DECLARE par varchar(255); SET par = (SELECT GROUP_CONCAT(mail SEPARATOR ',') FROM users WHERE id IN ( SELECT user_id FROM meeting_participants WHERE meeting_id = pid)); RETURN par; END And I'm trying to get the return of that function in the following procedure: CREATE PROCEDURE google_calendar (p1 varchar(50), p2 INT, p3 varchar(50), p4 varchar(50), p5 varchar(50), p6 varchar(50), p7 varchar(50), p8 varchar(50)) BEGIN DECLARE parti VARCHAR(255); SET @parti = get_participantes(p2); SELECT COALESCE(@parti,"nullpart") INTO @par2; SET @cmd = CONCAT('curl "http://*****:80**/meetings/api/" --data-urlencode "id=',p1,'" --data-urlencode "participants=',@par2,'" --data-urlencode "age...

How to decrease count getting from user input in java and my sql

How to decrease count getting from user input in java and my sql public void bookRooms(){ try{ System.out.println("Enter rooms to book "); int roomCount = scan.nextInt(); String queryTwo = "select mansion_names,rent,single_rooms-1,double_rooms from mansions where mansion_names =? "; // above query i am not able to pass user input roomCount from console instead number is working PreparedStatement ps2 = con.prepareStatement(queryTwo); ps2.setString(1, mName); ResultSet rs2 = ps2.executeQuery(); while(rs2.next()){ System.out.println(" "+rs2.getString(1)+" "+rs2.getInt(2)+" "+rs2.getInt(3)+" "+rs2.getInt(4));//+" "+rs.getInt(4)+" "+rs.getString(5)+" "+rs.getInt(6)+" "+rs.getInt(7)); } con.close(); }catch(Exception e){ System.out.println("error"); }; } in the above queryTwo i am not ...

How to delete space inside the string under condition, using SQL?

How to delete space inside the string under condition, using SQL? I am looking for your support. I am trying to find and replace part of string in URLs in the mySQL DB. I have over 550 URLs inputted in the code, where I need to delete the spaces. i.e.: https://www.poczytaj.pl/ksiazka/historia-national-geographis-splendor-bizancjum , 317145 ?pp=5 https://www.poczytaj.pl/ksiazka/stara-akademia-platona-w-poczatkach-epoki-hellenistycznej-ostatni-okres-bogdan-dembinski , 413137 ?pp=5 Can you please advice what code I should ran? My proposal which do not works: UPDATE `h15bpt4rj_posts` SET `post_content` = replace(post_content, ', ', ',') WHERE 'post_content' LIKE ', ______?pp=5'; Underscore is exchanging six digits, which are inside the URL. Can you help me to get URLs with SQL like: href="https://www.poczytaj.pl/ksiazka/historia-national-geographis-splendor-bizancjum**,317145**?pp=5" https://www.poczytaj.pl/ksiazka/stara-akademia-platona-w-poczatka...

SQL ont-to-may relationship - How to SELECT rows depending on multiple to-many properties?

SQL ont-to-may relationship - How to SELECT rows depending on multiple to-many properties? A MySQL database contains two tables with a one-to-many relationship: One user can have many settings: Users: id username password -------------------------- 1 Bob 123 2 Alice abc ... Settings: id user_id key value ----------------------------- 1 1 color blue // Bobs settings... 2 1 theme xy 3 1 size 5 4 2 size 6 // Alices settings... Problem: How to find all users with color == blue AND size == 5 ? color == blue AND size == 5 Using a LEFT JOIN it is no problem to find users with one property: LEFT JOIN SELECT users.id FROM users LEFT JOIN settings ON users.id = settings.user_id WHERE settings.key = 'color' AND settings.value = 'blue' However, this does not work when searching for two settings at a time? Is it possible to solve this with a single statement? What is the most efficient...

Values on browser are different as compared to the ones stored in database php

Values on browser are different as compared to the ones stored in database php i generated a random number to use as a tracker but the random number generated is not the same as the one stored in the database. Php Code: <div class="form-group"> <label for="name-card" class="text-success"><strong><?php echo $NUMEROENVIO; ?></strong></label> <?php $qryEmpresa = mysql_query("SELECT * FROM company"); while($row = mysql_fetch_array($qryEmpresa)) { $pre = $row["prefijo"]; $cons = $row["cons_no"]; } mysql_free_result($qryEmpresa); $pa=mysql_query("SELECT MAX(cons_no)as maximo FROM c_tracking"); if($row=mysql_fetch_array($pa)){ if($row['maximo']==NULL){ $cons_no=''.$cons.''; }else{ ...

radius add nas record to nas table fail

radius add nas record to nas table fail my compony has a radius that was used to auth, now I want to use that to strongswan vpn , and after I config the strongswan,I config the radius that add nas table a record like 10 | 172.16.2.10 | hlg-vpn | other | NULL | testing | NULL | NULL | RADIUS Client | and ok, the 172.16.2.10 is the ipaddress of the strongswan server, and the nas table also contain others nas records those work fine . the record I add to nas table seems doesn't work. when I auth the vpn with a radius account, the radius log is like Sat Jun 24 20:34:45 2017 : Error: Ignoring request to authentication address * port 1812 from unknown client 172.16.2.10 port 48394 Sat Jun 24 20:34:47 2017 : Error: Ignoring request to authentication address * port 1812 from unknown client 172.16.2.10 port 48394 Sat Jun 24 20:34:50 2017 : Error: Ignoring request to authentication address * port 1812 from unknown client 172.16.2.10 port 48394 Sat Jun 24 20:34:54 2017 : Er...

mysql query showing error: #1241 - Operand should contain 1 column(s)

mysql query showing error: #1241 - Operand should contain 1 column(s) Mysql query, SELECT qcat.name, COUNT( CASE WHEN qas.state = "todo" THEN 1 END ) AS gtotal, COUNT( CASE WHEN qas.state = "gradedright" THEN 1 END ) AS rightanswer, COUNT( CASE WHEN qas.state = "gradedwrong" THEN 1 END ) AS wronganswer, SUM(qas.fraction) AS grade, quiza.id FROM mdl_quiz_attempts quiza JOIN mdl_question_attempts qa ON qa.questionusageid = quiza.uniqueid JOIN mdl_question_attempt_steps qas ON qas.questionattemptid = qa.id JOIN mdl_question qstn ON ( qa.`questionid` = qstn.id ) JOIN mdl_question_categories qcat ON ( qstn.`category` = qcat.id ) WHERE quiza.id=1173 and FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) GROUP BY quiza.id,qcat.name showing error: #1241 - Operand should contain 1 column(s) Try replace FIND_IN_SET(qstn.id, (1,2,3,4,5,6)) with FIND_IN_SET(qstn.id, 1,2,3,4,5,6) (remove parenthesis) – Felippe Duarte J...

output name instead of id

output name instead of id I'm trying to see how long it takes to resolve a bug based on the area that it affects. My result set looks like this areaid Average Resolution/Closure Time (days) 1 425.57929613 2 510.00435347 3 342.90670739 I want to replace the area values with the name of the area rather than the id number. The name of the area is in another table (area table). the table i'm performing the code on is called bug table. So this is what I want. area_name Average Resolution/Closure Time (days) ABC 425.57929613 DEF 510.00435347 GHI 342.90670739 The area table looks like this areaid area_name 1 ABC 2 DEF 3 GHI i think i need to use a join (all bugs is tied to one area, but area categories may not be tied to a bug) so that my code is able to call the area name based on the primary key area id. My question is basically how...

How to prevent to store also the 0 in decimal?

How to prevent to store also the 0 in decimal? I need to save the avg of a value, that in this case corresponds to the average attendance of a venue, and for this, I created a new field called avg which has this structure: decimal(10,3) . avg avg decimal(10,3) Now if I store a value like this: 2671, the field will contain: 2.671 that's correct, but if I need to store only 800 I'll get: 800.000 that's, of course, is a different number… 800 800.000 So how can I store the correct decimal value? In this case should be only 800, not 800.000. Also, how can I adjust the bad values stored in the database without repeat all the insert? Thanks. 800 is 800.000. What happens to 2671 to make it 2.671 ? – Alex K. Jun 29 at 16:17 If you need to distinguish between "800" and ...

bash: Get last line of a huge gziped file

bash: Get last line of a huge gziped file In a database backup process I generate a text dumpfile. As database is quite huge, dump file is huge too so I compresses it with gzip. Compression is done inline while dump is generated (thanks Unix pipe !). At the process end, I check dump file validity by watching the last line and check the "Dump completed" string presence. In my script I do it by extracting last line into a variable: str=`zcat ${PATHSAVE}/dumpFull.sql.gz | tail -n1` As database dump file is huge (currently more than 200Gb) this end process check take huge time to run (currently more than 180 minutes). I'm searching a way to extract quicker the last line of my .gz file ... any idea anyone ? Note 1: For explain context, we can say database is MySql community, backup tool is mysqldump, generated dumpfile is a full text file. OS is CentOs. Backup script is Bash shell script. Note 2: I'm aware about Percona xtraBackup but in my case I want to use mysqldump f...

i cannot view my crystal report in my simple web page

i cannot view my crystal report in my simple web page what seem to be the problem with my code? i cannot view it in my browser. i searched google and so but cannot find the answer. it is been 2 days already that i am looking for solutions. can anyone help thanks. public partial class WebForm1 : System.Web.UI.Page { string connectionString = "server=" + ConfigurationManager.AppSettings["Server"] + ";uid=" + ConfigurationManager.AppSettings["User ID"] + ";pwd=" + ConfigurationManager.AppSettings["Password"] + ";database=" + ConfigurationManager.AppSettings["Database Name"] + ";Command Timeout=28800;"; protected void Page_Load(object sender, EventArgs e) { EmpReport crystalReport = new EmpReport(); dsEmp ds = GetData(); crystalReport.SetDataSource(ds); this.CrystalReportViewer1.ReportSource = crystal...