Jump to content

Search the Community

Showing results for tags 'mysql'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

  1. I have a table called "playlists", and a table called "musics". In the musics table, there is a column playlist_id which references the playlist that each music is contained. I'm using api calls to display information on the site with JavaScript, so I need to return a JSON. I need the json with the following structure: [ Playlists: [ { Name: "etc", musics: [ { name: "teste.mp3" }, { name: "test2.mp3" } ] }, ... ] ] And this is my code: $query = $con->prepare("SELECT * FROM playlists WHERE user_id = :id"); $query->execute(array("id" => $userID)); $playlists = $query->fetchAll(PDO::FETCH_ASSOC); foreach ($playlists as &$key) { $query = $con->prepare("SELECT * FROM musics WHERE playlist_id = :id"); $query->execute(array("id" => $key['ID'])); $songs = $query->fetchAll(PDO::FETCH_ASSOC); $key['musics'] = $songs; } There's a way to avoid this loop?
  2. Hi, I'm using $clid = mysqli_real_escape_string ($dbcon, $_POST['clid']); but have come across an issue with certain characters, for example: "bekæ" actually searches for "bekæ", hence no records. The records cannot be changed in the table, so is there a way to fix this?
  3. So i have this following code that doesn't work <?php $id = $_GET['id']; $data = $_GET['data']; $key = "Password"; mysql_query("update contest_data set '$key'='$data' where Contest_Data_ID='$id'") ?> it doesn't work unless i put it like this <?php $id = $_GET['id']; $data = $_GET['data']; $key = "Password"; mysql_query("update contest_data set `Password`='$data' where Contest_Data_ID='$id'") ?> is there a way to put the `` when setting the $key value i even tired to put $key = "`Password`" and that doesn't work. Also $key="password" is going to be $key= $_GET['key'] but for now i put it like this so i can test it out
  4. I would like to send an email when % is >than 50%, if so get fields from Txt fiel and fields from DB and send an email to the address in the txt file. <html> <head><title>Email Alert</title></head> <body> <?php require 'PHPMailerAutoload.php'; $mail = new PHPMailer; //$mail->SMTPDebug = 3; // Enable verbose debug output mysql_connect("ip","user","pass") or die(mysql_error()); //mysql_select_db("DB") or die(mysql_error()); //$sql = "SELECT * from pool"; $sql = mysql_db_query ("demo", "select * from pool "); while ($row = mysql_fetch_assoc($sql)) { $sql = "SELECT '%' FROM pool Where >= 50 "; { //echo $row->number; $percent = $row['%'] ; $pool2 = $row['pool']; $balance = $row['balance']; /////////////////////////// //data from file ////////// ////////////////////////// $file = fopen('EmailAndPool2.csv', 'r'); $fields = array(); if ($file) { while (($data = fgetcsv($file)) !== false) { if(empty($fields)) { $fields = $data; continue; } $row = array_combine($fields, $data); // Format output conveniently with sprintf $output = sprintf("%s Pool %s email.\n", $row['pool'], $row['email']); echo $output; } fclose($file); $pool1 = $row['pool']; //while ($pool2 == $pool1 and $percent > "50") $pool2 =$row['pool2']; $mail = new PHPMailer; $mail->isSMTP(); // Set mailer to use SMTP $mail->Host = 'xxxxxxxxx; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'xxxxxxxxxxxxxxxxx'; // SMTP username $mail->Password = 'xxxxxxxxxxxxxxxx; // SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 587; // TCP port to connect to $mail->FromName = 'Support'; $mail->addAddress ($row['email']); //$mail->addAddress = $members; //$mail->addCC('xxxxxxxxxxx'); //$mail->addCC('xxxxxxxxxxxxxxxx'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->isHTML(true); $mail->Subject = 'test'; $mail->Body = 'test '; $email_from = 'xxxxxxxxxxxx'; } if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } } } ?> </body> </html> Thank you
  5. Hi I have a form that has a drop-down with a few to choose from, unfortunately I don't get results for some due to the query involved. Some need the AND channel LIKE '%$channel%'"; and some don't and therefore will not get desired results. So I would like to run two queries one with and one without. $query = "SELECT * FROM asterisk_cdr WHERE calldate BETWEEN '$calldate' AND '$calldate2' AND clid LIKE '%$clid%' AND channel LIKE '%$channel%'"; Thanks
  6. I'm making statistic for 5 tables. I have made the example with one client data. loan: payment_schedule: payment_schedule_row payment_schedule_cover: payment_schedlue_delay: And the query is: SELECT period, loan_sum, covers, delay FROM (SELECT MAX(EXTRACT(YEAR_MONTH FROM psc.date)) AS period, (SELECT SUM(psr2.payment) FROM payment_schedule_row AS psr2 WHERE psr.payment_schedule_id = psr2.payment_schedule_id) AS loan_sum, (SELECT SUM(psc2.sum) FROM payment_schedule_cover AS psc2 WHERE psc.payment_schedule_id = psc2.payment_schedule_id) AS covers, (SELECT SUM(psd2.delay) FROM payment_schedule_delay AS psd2 WHERE psr.id = psd2.payment_schedule_row_id) AS delay FROM loan INNER JOIN payment_schedule AS ps ON ps.loan_id = loan.id INNER JOIN payment_schedule_row AS psr ON psr.payment_schedule_id = ps.id INNER JOIN payment_schedule_cover AS psc ON psc.payment_schedule_id = ps.id WHERE loan.status = 'payed' GROUP BY ps.id) AS sum_by_id GROUP BY period Sqlfiddle link: http://sqlfiddle.com/#!2/21585/2/0 Result for the query: period | loan_sum | covers | delay --------------------------------------- 201407 | 384 | 422 | 0.07 Everything is right except the delay. It should be 0.11 (0.07 + 0.03 + 0.01) So I have been trying to find the error from the query for days now. Maybe someone can tell me what I'm doing wrong.
  7. So just to preface this, I have been part of two operations (one as developer, one with a 3rd party company developing) where the business was forced to cease due to difficulties in database load balancing and lots of people lost lots of money. I am talking about big data and high performance needed at the same time. So for my new project, I am going to try and design it around having a forever expanding infrastructure of servers but that means setting it correctly from the beginning. I have put together some ideas for possible ways to split the database load across multiple servers. Any input to which idea(s) are best would be great so I know which to explore further. Also any relevant info on this type of thing would be helpful as this is the first time I am personally doing this. Thanks!
  8. I am building an e-commerce site and I am aiming to create a front end displaying my products with an option for customers to buy them, and have a content management system as a back end for an admin to edit product information. Currently I am storing information about my products on a mysql database. I access and display the product info using a while loop. Below is a simplified version of what I am doing without any html to style it. This code will go through the database and each iteration will go the to the next row and display the info about the next product. $query = mysql_query("SELECT * FROM truffleProducts"); while ($row = mysql_fetch_array($query)) { $id = $row['id']; $name = $row{'Name'}; $price = $row{'Price'}; $desc = $row{'Description'}; echo $id; echo $name; echo $price; echo $desc; } I have began to implement a 'buy' button so that customers are able to click on a button next to the product info and purchase it. However I have come across a problem which is where my program won't be able to tell which product you have selected as the number stored in the $id variable will just be the last product it has fetched from the database. I can't differentiate between all the product's buy buttons, so it will impossible to place an order for a customer with the current system I have. Can any one tell me how to get the id number of the specific product that a user has selected? I only started learning PHP a month or two ago so assume I know nothing
  9. Hi Using: echo $row['columnname']; How can I strip off data from the above echo? The column always begins with 'Local/' then 3 digits then other unwanted data, lke 'Local/567@context-0000461d;1'. It would be ideal to just display '567'.
  10. Hi guys I have this code below and all works fine when submitting this online application apart from when someone types either ' # & into one of the comment fields in which it throws up the error. Have tried various fixes from across the internet but no joy. Can anyone offer suggestions? <?php $con = mysql_connect("localhost:3306","root","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db('sfapp', $con); $sql="INSERT INTO 'sfapp' ('surname_add','forename_add','dob_add','hometele_add','mobiletele_add','homeadd_add','siblings_add','schoolname_add','headname_add','schooladd_add','schooltele_add','schoolem_add','alevel_add','personstate_add','nameprovided_add','pe_add','se_add','PredGrade_Art','PredGrade_AScience','PredGrade_BusStudies','PredGrade_Electronics','PredGrade_EnglishLang','PredGrade_EnglishLit','PredGrade_French','PredGrade_German','PredGrade_Geog','PredGrade_Graphics','PredGrade_History','PredGrade_Maths','PredGrade_SepScience','PredGrade_ProductDesign','PredGrade_Spanish','PredGrade_Other','Gender_Male','Gender_Female','Sub_EnglishLit','Sub_Maths','Sub_FurtherMaths','Sub_Biology','Sub_Chemistry','Sub_Physics','Sub_French','Sub_German','Sub_Spanish','Sub_Geography','Sub_History','Sub_RE','Sub_FineArt','Sub_Business','Sub_Computing','Sub_GlobPersp','Sub_DramaAndTheatre','Sub_PE','Sub_Dance','Sub_Politics','Sub_Psychology','Sub_Sociology','readprospect_chk','Sib_Yes','Sib_No','Current_Student_Yes','Current_Student_No','I_Understand_chk','Current_Education_chk','Local_Care_chk','Staff_Cwhls_chk','Sub_Film') VALUES ('$_POST[surname_add]','$_POST[forename_add]','$_POST[dob_add]','$_POST[hometele_add]','$_POST[mobiletele_add]','$_POST[homeadd_add]','$_POST[siblings_add]','$_POST[schoolname_add]','$_POST[headname_add]','$_POST[schooladd_add]','$_POST[schooltele_add]','$_POST[schoolem_add]','$_POST[alevel_add]','$_POST[personstate_add]','$_POST[nameprovided_add]','$_POST[pe_add]','$_POST[se_add]','$_POST[PredGrade_Art]','$_POST[PredGrade_AScience]','$_POST[PredGrade_BusStudies]','$_POST[PredGrade_Electronics]','$_POST[PredGrade_EnglishLang]','$_POST[PredGrade_EnglishLit]','$_POST[PredGrade_French]','$_POST[PredGrade_German]','$_POST[PredGrade_Geog]','$_POST[PredGrade_Graphics]','$_POST[PredGrade_History]','$_POST[PredGrade_Maths]','$_POST[PredGrade_SepScience]','$_POST[PredGrade_ProductDesign]','$_POST[PredGrade_Spanish]','$_POST[PredGrade_Other]','$_POST[Gender_Male]','$_POST[Gender_Female]','$_POST[sub_EnglishLit]','$_POST[sub_Maths]','$_POST[sub_FurtherMaths]','$_POST[sub_Biology]','$_POST[sub_Chemistry]','$_POST[sub_Physics]','$_POST[sub_French]','$_POST[sub_German]','$_POST[sub_Spanish]','$_POST[sub_Geography]','$_POST[sub_History]','$_POST[sub_RE]','$_POST[sub_FineArt]','$_POST[sub_Business]','$_POST[sub_Computing]','$_POST[sub_GlobPersp]','$_POST[sub_DramaAndTheatre]','$_POST[sub_PE]','$_POST[sub_Dance]','$_POST[sub_Politics]','$_POST[sub_Psychology]','$_POST[sub_Sociology]','$_POST[readprospect_chk]','$_POST[sib_Yes]','$_POST[sib_No]','$_POST[Current_Student_Yes]','$_POST[Current_Student_No]','$_POST[i_Understand_chk]','$_POST[Current_Education_chk]','$_POST[Local_Care_chk]','$_POST[staff_Cwhls_chk]','$_POST[sub_Film]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } ?> <?php //if "email" variable is filled out, send email if (isset($_REQUEST['pe_add'])) { //Email information $admin_email = $_REQUEST['pe_add']; $forename = $_REQUEST['forename_add']; $email = "autoreply@testing.com"; $subject = "Application"; $desc = "Dear $forename Thank you for submitting your online application, we will be in touch shortly. " ; //send email mail($admin_email, "$subject", "$desc", "From:" . $email); //Email response echo "Thank you for contacting us!"; } //if "email" variable is not filled out, display the form else { ?> If you are seeing this, you need to go back and fill out the Personal Email section! <?php } header("location:complete.php"); mysql_close($con) ?> Thanks in advance.
  11. I need to check whether the user has uploaded a file when submitting a form using isset. If they have, the file path is recorded to the database. If they haven't nothing needs to occur, the file path field will just be NULL. Here is my issue: When I test it with uploading no file I'm still getting "images/" from my $ filelocation variable recorded to the database. How can I fix this? <?php if(isset($_FILES['userfile'])) { $fileupload = $_FILES['userfile']['name']; $filetype = $_FILES['userfile']['type']; $filesize = $_FILES['userfile']['size']; $tempname = $_FILES['userfile']['tmp_name']; $filelocation = "images/$fileupload"; } else { $filelocation = NULL; } if (!move_uploaded_file($tempname,$filelocation)) { switch ($_FILES['userfile']['error']) { case UPLOAD_ERR_INI_SIZE: echo "<p>Error: File exceeds the maximum size limit set by the server</p>" ; break; case UPLOAD_ERR_FORM_SIZE: echo "<p>Error: File exceeds the maximum size limit set by the browser</p>" ; break; default: echo "<p>File could not be uploaded </p>" ; } } if ($_POST["productName"] == "") { header("Location:getProductDetails.php"); exit(); } elseif ($_POST["productDescription"] == "") { header("Location:getProductDetails.php"); exit(); } else { $conn = @mysqli_connect("localhost", "root", ""); if (!$conn) { echo "The connection has failed: " . mysqli_error($conn); } else { //echo "Successfully connected to mySQL!"; $query = "CREATE DATABASE IF NOT EXISTS bazaar"; $dbName =""; if (!mysqli_query($conn,$query)) { echo "<p>Could not open the database: " . mysqli_error($conn)."</p>"; } else { //echo "<p>Database successfully created</p>"; if (!mysqli_select_db($conn,"bazaar")) { echo "<p>Could not open the database: " . mysqli_error($conn)."</p>"; } else { //echo "<p>Database selection successful</p>"; $query = "CREATE TABLE IF NOT EXISTS products(productid int primary key not null auto_increment,productname varchar(50), productdesc text, colour varchar(25), price decimal(5,2) not null,imagepath varchar(250));"; if (!mysqli_query($conn,$query)) { echo "table query failed1: " . mysqli_error($conn); } else { //echo "<p>table query successful</p>"; $insert = "INSERT INTO products (productname, productdesc, colour, price, imagepath) VALUES ('$_POST[productName]','$_POST[productDescription]','$_POST[colour]','$_POST[price]','$filelocation');"; if (mysqli_query($conn,$insert)) { $customerId = mysqli_insert_id($conn); } else { echo "table query failed: " . mysqli_error($conn); } } } } } mysqli_close($conn); } ?>
  12. Hi, I am trying to create a login system in PHP, but I am not the greatest at PHP so I am using a source code which I found online as I found it to be more secure as it uses things like salted passwords. Anyway I am trying to add more fields to the register system so it adds them to the mysql, the source has a way to do this with arrays, but it is quite complicated so I am just using variables from the original file. There are 2 files: register.php and class.loginsys.php which contains all the functions. At first the query syntax was incorrect so I decided to use the variables created in register.php in the class.loginsys, but now it's giving me an out of memory error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 28672 bytes) in C:\xampp\htdocs\ls\class.loginsys.php on line 34 Which I am unsure of how to fix. I have tried using different variable names, checking the line, checking the whole register.php file for anything rogue. Here is the code: Top part of register.php <?php include "config.php"; ?> Config.php: <?php require "class.loginsys.php"; $LS=new LoginSystem(); ?> Then actual register part from register.php: <?php if( isset($_POST['submit']) ){ $firstname2 = $_POST['firstname']; $lastname2 = $_POST['lastname']; $user2 = $_POST['username']; $sex2 = $_POST['sex']; $country2 = $_POST['strCountryChoice']; $email2 = $_POST['email']; $pass2 = $_POST['pass']; $pass3 = $_POST['pass2']; $birthdate2 = $_POST['birthdate']; $created2 = date("Y-m-d H:i:s"); //need to add a lot more validation functions.. AKA Check if email exists and username. Password > 5 chars if( $user2=="" || $email2=="" || $pass2=='' || $pass3=='' || $firstname2=='' || $lastname2=='' || $sex2=='' || $country2=='' || $birthdate2=='' ){ echo "Fields Left Blank","Some Fields were left blank. Please fill up all fields."; exit; } if( !$LS->validEmail($email2) ){ echo "E-Mail Is Not Valid", "The E-Mail you gave is not valid"; exit; } if( !ctype_alnum($user2) ){ echo "Invalid Username", "The Username is not valid. Only ALPHANUMERIC characters are allowed and shouldn't exceed 10 characters."; exit; } if($pass2 != $pass3){ echo "Passwords Don't Match","The Passwords you entered didn't match"; exit; } $createAccount2 = $LS->register($user2, $pass2, array( "email" => $email2, "name" => $firstname2, "lastname" => $lastname2, "gender" => $sex2, "country" => $country2, "DOB" => $birthdate2, "created" => date("Y-m-d H:i:s") // Just for testing ) ); //$createAccount = $LS->register($firstname,$lastname,$user,$sex,$country,$email,$pass,$birthdate,$created); if($createAccount2 === "exists"){ echo "User Exists."; }elseif($createAccount2 === true){ echo "Success. Created account."; } } ?> And the function from the class: /* A function to register a user with passing the username, password and optionally any other additional fields. */ public function register( $id, $password, $other = array() ){ if( $this->userExists($id) && (isset($other['email']) && $this->userExists($other['email'])) ){ return "exists"; }else{ $randomSalt = $this->rand_string(20); $saltedPass = hash('sha256', "{$password}{$this->passwordSalt}{$randomSalt}"); if( count($other) == 0 ){ /* If there is no other fields mentioned, make the default query */ //old query: ("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)"); //new query: ("INSERT INTO `{$this->dbtable}` (`username`, 'email' , `password`, `password_salt` , 'name' , 'lastname' , 'gender' , 'country' , 'DOB') VALUES(:username, :email, :pass, :passwordSalt, :firstname, :lastname, :gender, :country, :DOB)"); $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`) VALUES(:username, :password, :passwordSalt)"); }else{ /* if there are other fields to add value to, make the query and bind values according to it */ //old query: ("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)"); //new query: ("INSERT INTO `{$this->dbtable}` (`username`, 'email' , `password`, `password_salt` , 'name' , 'lastname' , 'gender' , 'country' , 'DOB') VALUES(:username, :email, :pass, :passwordSalt, :firstname, :lastname, :gender, :country, :DOB)"); $keys = array_keys($other); $columns = implode(",", $keys); $colVals = implode(",:", $keys); //l= $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (`username`, `password`, `password_salt`, $columns) VALUES(:username, :password, :passwordSalt, :$colVals)"); //INSERT INTO MyGuests (firstname, lastname, email)cLUES ('John', 'Doe', 'john@example.com') $sql = $this->dbh->prepare("INSERT INTO `{$this->dbtable}` (username,email,password,password_salt,name,lastname,created,gender,country,DOB) VALUES ('$username2','$email2','$pass2','$saltedPass','$firstname2','$lastname2','$created2','$gender2','$country2','$birthdate2')"); print($sql); foreach($other as $key => $value){ $value = htmlspecialchars($value); $sql->bindValue(":$key", $value); } } /* Bind the default values */ $sql->bindValue(":username", $id); $sql->bindValue(":password", $saltedPass); $sql->bindValue(":passwordSalt", $randomSalt); $sql->execute(); return true; } } Thanks for your help. I am doing this because for a hobby I am trying to create a browser based game in which I use this login system to login the user to a main page then code all of the other pages myself. I have posted on stackoverflow and someone on their suggested that I should use a framework. If this is the case, can someone point me in the right direction? Thanks again, if you need any info ask.
  13. Hi, I have results from a MySQL table column which does an echo into a table cell, but some of the results from the table column is be empty, so is there a way to fill in the blanks with text like "No data"?
  14. Hello fellow programmers I recently bought a chat site without investigating (i know stupid me). this chat is made in Php / Mysql language and ajax, My question is, is there a possibility to convert the mysql to an IRC server. I dont know how to explane it 100% but is it possible to make the webchat thats coded in ajax & mysql work for a IRC server I have knowledge of mysql / php only is this above my level. My problem is that mysql is no option for chats, I need this webchat work with IRC but I have no idea where i should start. Maby someone can kick me in the right direction Thanks for your time & help Greets BTW this is the chatsite more people bought (this aint my site) but 100% the same : http://tinyurl.com/kk4gchd
  15. i want a situation where, when i upload something into my database, it creates a new table, everytime, i saw this $forum = "CREATE TABLE IF NOT EXISTS for_".$id." ( `id` int(11) NOT NULL AUTO_INCREMENT, `stud` int(11) DEFAULT NULL, `course` int(11) DEFAULT NULL, `message` varchar(1000) DEFAULT NULL, PRIMARY KEY (`id`) ) "; but don't know how to implement it into this query $sql = "INSERT into data(name,Groups,phone_number) values('$data[0]','$data[1]','$data[2]')";
  16. Say you have three tables like this... STUDENTS (studentid, name) CLASSES (studentid, classname) GRADES (studentid, grade) And not all students have grades yet. If you're doing a mysql query like below, is there anything you can add to the statement to check if a grade exists for each student? So that if while lopping through the results of the main query, I can easily do something with the students who don't yet have a grade yet (like maybe mark their names in red). I can do this by putting a whole separate mysql query inside the looping of the main query, but that seems terribly inefficient to call the database again for EVERY student. $sql = "SELECT * FROM students, classes, grades WHERE students.studentid = classes.studentid ORDER BY students.lastname"; $info= mysqli_query($connection, $sql); if (!$info) { die("Database query failed: " . mysqli_error()); } else { //code } Thanks! Greg
  17. I have a mysql field that I want to store a php variable in and then retrieve it. Example: Color table has the field named colorBackground with the value of #FF0000 CSS table has the field named cssBackground with the value of .background { background-color: #444444; } What I want to do is make Color/colorBackground a variable {{$backgroundcolor = rsColor['colorBackground'] Then I want to change the CSS/cssBackground value to .background { background-color:$backgroundcolor; } Creating the $backgroundcolor works fine. I'm just not sure how to put the $backgroundcolor in my CSS/cssBackground field.
  18. I am still trying to fully comprehend table normalization and I'm not asking anyone to explain it bc it's not a simple thing to explain. But I'm working on a football website that tracks players stats each week (catches, yards and touchdowns) and it seems like setting it up this way would make it the easiest (maybe laziest?) to retrieve data to display wherever I want... tablecalled players with these fields: playerid playerfirstname playerlastname week1catches week1yards week1touchdowns week2catches week2yards week2touchdowns ... and so on 17 times till... ... week17catches week17yards week17touchdowns I know that is likely making most of you want to puke but if doing it this way makes it extremely easy to pull this info for display on the site, why is it so wrong? Is the problem that it's much slower than what I THINK is the proper way, ie... table called players with these fields: playerid playerfirstname playerlastname AND table called stats with these fields: playerid week catches yards touchdowns Again, not asking for an explanation of normalization, just if anyone has any quick reasons why the first way is as god awful as I fear it is, I'd appreciate the knowledge. Thanks!
  19. Hi Been trying to run a query to get all rows from a table between two dates, but nothing seems to work. $query = "SELECT * FROM table WHERE date BETWEEN '%2014-11-17%' AND '%2014-11-18%'"; Strange thing if I try a search instead a query in phpmyadmin I don't see an operator called 'BETWEEN' on the remote host, but I do on my localhost. Does this mean it will never work on the remote host? Nevertheless it doesn't work on either and I do have records for both dates in the table. phpmyadmin: Version 4.1.14 localhost (wamp) Version 3.3.7deb7 on remote server Thanks
  20. Is it possible to have a link at the top of a page that has been displayed from a database? Just that some results show thousands of rows. Thanks.
  21. I am trying to check to see if someone has registered and log them in to a site. I am using the following syntax. $resultID = mysql_query("SELECT * FROM user where username = '$username' AND password like '$password'", $linkID)or die(mysql_error()); If I omit the AND password like '$password' it brings me down records but when I add this bit in it fails everytime. I have used this before with no problems.. Any help greatly appreciated. Angie
  22. I am in the process of trying to create a pedigree website (php/mysql)... I want to be able to calculate a dog's inbreeding coefficient on 10 generations. I am so not sure where to even begin. I have a database table: dogs: Fields: id name sireid damid equation: FX = å [ (½) n1+n2+1 (1 + FA)] http://www.highflyer.supanet.com/coefficient.htm Can someone give me a starting point? Do I need to learn bianary trees? could I do this with an array? Thanks
  23. I am creating a website for university coursework. <input name="submit" type="submit" class="submit_btn float_l" id="submit" formaction="add-contactme.php" value="Send" /> The above code is from my html for contact.html if that is correct. I am using a form and then a submit button. I keep getting Notice: Undefined index: name in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 11 Notice: Undefined index: email in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 12 Notice: Undefined index: phoneno in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 13 Notice: Undefined index: comments in C:\xampp\htdocs\hometown\hometown\add-contactme.php on line 14 Also if anyone could help me I would like to create a delete button after a person has added the values into the sql table, basically to the last row inputted into the database. I want to avoid using delete from contactme where name ='chris'; $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="test"; // Database name $tbl_name="contactme"; // Table name mysql_connect ("$host", "$username", "$password") or die ("cannot connect server "); mysql_select_db ("$db_name") or die ("cannot select DB"); $name = $_POST["name"]; $email = $_POST["email"]; $phoneno = $_POST["phoneno"]; $comments = $_POST["comments"]; $sql="INSERT INTO $tbl_name VALUES ('$name', '$email', '$phoneno''$comments')"; $result=mysql_query($sql); if($result){ echo "Successful" . " "; echo "view-contactme.php"; // link to view contact me page } mysql_close(); ?>
  24. I have 2 queries that I want to join together to make one row This queries returns all rows from both tables which is what i want SELECT table_A.*, table_B.* FROM table_A INNER JOIN table_B ON table_A.code = table_B.code and this is the output table_A.id | table_A.code | table_B.id | table_B.code | table_B.complete =============================================================================================== 1 | 123456 | 1 | 123456 | yes 2 | 654321 | 2 | 654321 | no and this is the second query SELECT table_C.*, table_D.* FROM table_C INNER JOIN table_D ON table_C.code = table_D.code INNER JOIN table_B ON table_D.code = table_B.code WHERE table_B.complete = 'yes' and again the output table_C.id | table_C.code | table_D.id | table_D.field2 | table_B.complete ======================================================================================== 1 | 123456 | 1 | 123456 | yes What I've been trying to for the last couple of days is join the 2 queries together to make one query that returns this table_A.id | table_A.code | table_B.id | table_B.code | table_B.complete | table_C.id | table_C.code | table_D.id | table_D.field2 | table_B.complete ==================================================================================================================================================================================== 1 | 123456 | 1 | 123456 | yes | 1 | 123456 | 1 | 123456 | yes 2 | 654321 | 2 | 654321 | no All i want it to do is get all rows from tables A and B and return all rows from C and D only if table_B.complete equals "yes". All tables are joined by the code column which all have the same value
  25. Hi Members, I am search for the reason for the problem why my mysql query cannot fetch data and store in file based on id in $variable form. For example, $sql="SELECT * FROM mytable WHERE mine_id='1234'"; works for me. But when i use $sql="SELECT * FROM mytable WHERE mine_id='$id'";, files are created as empty. I chanaged the quotes and could not store the data in file. So anyone please help me. For more clear, i attach the part of my code for ($i=0;$i<=10;$i++) { $id=$seqs[$i]; $dbo = new PDO($dbc, $user, $pass); echo $sql = "SELECT * FROM mine_id WHERE locus_id='$id'"; $qry = $dbo->prepare($sql); $qry->execute(); $data = fopen('file.csv', 'w'); while ($row = $qry->fetch(PDO::FETCH_ASSOC)) { fputcsv($data, $row); } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.