Jump to content

Search the Community

Showing results for tags 'query'.

  • 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. Howdy, OK, I have been struggling with this problem all evening yesterday and this morning. Please help! I have a table subscribers that holds the emails of subscribed users. Then I have the table posts that holds the blog posts. I want to make it so that with one query I pull out all the emails from the subscribers table and only ONE record from the posts table namely the post_id and the post title so that I can that way construct a link to where the user can click on their email that will take them to the latest blog post. I can make it with two queries, but I really want to do it with one. I tried everything, sub-queries, joins, crosses, prayers with no good. I wrote this: SELECT DISTINCT (SELECT DISTINCT MAX(post_id) FROM posts ) AS last_post , subscribers_email FROM subscribers But it always pulls out duplicate post_id rows like this: post_id subscriber_email 66 example1@gmail.com 66 example2@gmail.com Here is my PHP code: function send_mass_email($db){ $sql = 'SELECT subscribers_email, post_id, title FROM subscribers, posts WHERE CONDITION'; $query = $db->prepare($sql); $query->execute(); $suject = 'New blog post in www.dyulgerova.info'; $message = ' New blog post have been posted in www.dyulgerova.info/blog Link - *LINK HERE* '; while($row = $query->fetch(PDO::FETCH_NUM)){ mail($row[0], $subject, $message); } } Thank you very much!
  2. can anyone help me come up a good php condition that if a specific aic from tb_applicants with a total=7 from this query SELECT count(t.atic) as total,t2.name FROM app_interview as t, tb_applicants as t2 WHERE t.atic = t2.aic GROUP BY t.atic; will execute this query INSERT INTO afnup_worksheet (faid,faic,fnl_name,ftotal) SELECT DISTINCT t.atid ,t.atic ,t.atname ,(SELECT SUM(t2.inttotal) FROM app_interview t2 WHERE t2.atic = t.atic)/7 thissum FROM app_interview t GROUP BY atname HAVING COUNT(DISTINCT atic)=1 i want to execute insert query to those specific applicants if those applicants with a total of 7 on the count query matches..can anyone help me?please im still learning..so be easy on me
  3. I have a table called tb_applicants with fields 'id','aic','name','total' This query total all the total of applicant with same aic field value and divide it with 7 and save the average score to a new table called: fapptotal with field 'id','aic','name','ftotal' My problem is i have the mysql query for it but i dont know how to use it in php..can anyone help me convert my query to php query. here is my query: INSERT INTO fapptotal (id,aic,name,ftotal) SELECT DISTINCT t.id ,t.aic ,t.name ,(SELECT SUM(t2.total) FROM tb_applicants t2 WHERE t2.aic = t.aic)/7 thissum FROM tb_applicants t GROUP BY name HAVING COUNT(DISTINCT aic)=1
  4. Hello to all! I have a question about how to do something with php and mysql. On my site, user can upload photos and choose if they want to let others users rate this photos (from 1 to 10). So actually, on my website, i have a section to shows members with best rating... .but the problem that users told me... is if a members has 3 pics with 3 different rate (let say 9, 8 and 7) this members will be show 3 time.... once at the position 9, another time to the position 8 and a last time at the position 7.... So the list can be very long..... My question is: Now i try to make is simple and better.. so i will show photo with best rate as i already did, but the difference is a same members will only appears once... so if a members has 3 pics... i will show the pics with the best rate and i want to add at the bottom of this pic a list of all other photo of this member that has been rated... So, if i take the same exemple, i will show the photo that rated 9 and below, in small thumbnail the 2 other pics that rated 8 and 7.. after i will continue to with the next result... maybe 8.9 ... or other.. I thought to every row, to query to get other photo of the actual user.... but it will query a lot of time the server.. so i dont think it's the best way.... Can you please give me a hint! Note: i have 1 table 'Photos' and every photo have his own row(id,path, rate.....) thanks for you help Pascal
  5. Hey guys, I am currently facing an issue with my profile.php page for my website. i have a function that is grabbing information of a logged in user grabbing his ID and his data array combining the 2 and creating a variable that will let me echo out the info for the end user on their profile page. the function that is creating an error : function user_data($user_id){$data = array(); $user_id = (int)$user_id; $func_num_args = func_num_args(); $func_get_args = func_get_args(); if ($func_num_args > 1) { unset($func_get_args[0]); $fields = '`' . implode('`, `', $func_get_args) . '`' ; $query = ("SELECT $fields FROM `users` WHERE `user_id` = $user_id"); echo $query . '<br><br>' ; < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE $run = mysql_query($query); print_r($run); < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE echo '<br><br>'; < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE $data = mysql_fetch_assoc($run); print_r($data) . '<br><br>'; < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE return $data; die(); < ---- ADDED FOR DEBUGGING --------- NOT PART OF CODE } } The function seems to work properly when printing the array and the query , firing the query independently in sql and getting a TRUE; Results: Line 156 of this file is that Function above ^ I dont understand why i am getting this error : I understand that i need the $query to fire correctly and return a resource to the fetch_assoc() , but as it shows above the resource is being provided and is still returning as a string ???. any suggestions ?
  6. I have been working on a code for a blog from scratch and now I have gotten the code to not throw errors but it is also not returning results. In this blog post I have created tags that can be attached to each blog post for easy reference. I have created a count of the tags on the right hand side which gives the name and a count for how many blog post use that tag. It is a link that you can click and the next step that I am having an issue with is just showing those blog post associated with that tag. I have written the code and as of right now is throwing no errors so I cannot look up how to fix it even though I have been working on it for hours. Here is the call that I am using once you click the link to pull up the results. blog_tags.php <?php include "includes.php"; $blogPosts = GetTaggedBlogPosts($_GET['tagId'], $DBH); foreach ($blogPosts as $post) { echo "<div class='post'>"; echo "<h2>" . $post->title . "</h2>"; $body = substr($post->post, 0, 300); echo "<p>" . nl2br($body) . "... <a href='post_view.php?id=" . $post->id . "'>View Full Post</a><br /></p>"; echo "<span class='footer'><strong>Posted By:</strong> " . $post->author . " <strong>Posted On:</strong> " . $post->datePosted . " <strong>Tags:</strong> " . $post->tags . "</span><br />"; echo "</div>"; } ?> Next is the function for displaying the link and counting the tags includes.php function getTagCount($DBH) { //Make the connection and grab all the tag's TAG TABLE HAS TWO FIELDS id and name $stmt = $DBH->query("SELECT * FROM tags"); $stmt->execute(); //For each row pulled do the following foreach ($stmt->fetchAll() as $row){ //set the tagId and tagName to the id and name fields from the tags table $tagId = $row['id']; $tagName = ucfirst($row['name']); //Next grab the list of used tags BLOG_POST_TAGS TABLE HAS TWO FILEDS blog_post_id and tag_id $stmt2 = $DBH->query("SELECT count(*) FROM blog_post_tags WHERE tag_id = " . $tagId); $stmt2->execute(); $tagCount = $stmt2->fetchColumn(); //Print the following list echo '<li><a href="blog_tags.php?tagId=' . $tagId . '"title="' . $tagName . '">' . $tagName . '(' . $tagCount . ')</a></li></form>'; //End of loop - start again } } This next part is the function used to pull and display the blog post. includes.php function GetTaggedBlogPosts($postTags, $DBH) { $stmt = $DBH->prepare("SELECT blog_post_id FROM blog_post_tags WHERE tag_id = :postTagId"); $stmt->bindParam(":postTagId", $postTags, PDO::PARAM_INT); $stmt->execute(); if(!empty($stmt)) { $blogstmt = $DBH->prepare("SELECT * FROM blog_post WHERE id = :blog_id ORDER BY id DESC"); $blogstmt->bindParam(":blog_id", $stmt, PDO::PARAM_INT); $blogstmt->execute(); } else { echo "Something went wrong....Please contact the administrator so that we can fix this issue."; } $postArray = array(); $result = $blogstmt->fetchAll(PDO::FETCH_ASSOC); foreach($result as $row){ $myPost = new BlogPost($row["id"], $row['title'], $row['post'], $row['author_id'], $row['date_posted'], $DBH); array_push($postArray, $myPost); } return $postArray; } Any ideas why it is not displaying?
  7. I thought I had this issue figured out last night with the help from this forum, but turns out it still isn't working as expected. I have two tables: Table: sapImport id invoiceNo invoicedAtID invoicedAtName soldOn soldBy customer 1 CICIN123 3 Cicero 1384832632 brian john smith 2 DESTIN12 5 Destiny 1384832632 brian Henry Will 3 VESTIN32 3 Cicero 1384832632 jason Peter Jenn Table: conStatus id store record statusCode 34 3 1 0 35 5 3 0 39 3 1 15 I do have more rows than this, but i'm just trying to give an idea ... I currently have the following query: SELECT * FROM sapImport si INNER JOIN conStatus cs ON si.id = cs.record INNER JOIN ( SELECT record, MAX(id) as id FROM conStatus GROUP BY record ) mx ON cs.record = mx.record AND cs.record = mx.id WHERE cs.store='$storeID' AND cs.statusCode < '998' Basically, the table sapImport contains customer information and the conStatus table contains all interactions with a record in the sapImport table. The 'id' row in sapImport is the primary key and is auto-incremented. The 'record' row in conStatus references the 'id' row from sapImport. I need a query that pulls the LAST record (from conStatus) for a particular customer (from sapImport) where the store=x and the statusCode is less than 998. I should only get ONE result set with this. Any help will be GREATLY appreciated! Thanks in advance!
  8. I am just curious how one would go about this.. Let's say I have a mysql table called articles and 3 columns: postid, title, content ...and I wanted to format my url to look like mysite.com/this-is-my-title I understand that the normal approach is to query for postid and include that in the url.. and probably use a rewrite rule in htaccess, but is it possible to simply query the database for the title only and append to the url after .com/ ? I understand that in such a case, every title would have to be unique, but still curious about the approach. Since the url would have to be sanitized and dashes added, can you still make a request by title? Thanks!
  9. I am having trouble writing exactly 4 queries in mysql. Here is the view I am using for queries: http://pastie.org/8403299 Here is the Raw Data you can check http://goo.gl/z7Vv9X which you can check. What is needed: 1) Gained students are those who exist in the selected / filtered month and don't exist in the previous month. 2) Lost students are those who exist in the previous month of the selected / filtered month and don't exist in the selected / filtered month. 3) Get a list of all lost students since the start of the center till now(). 4) Get a list of all gained students since the start of center till now. I am currently stuck with query 1) (Gained students are those who exist in the selected / filtered month and don't exist in the previous month.) I have written it like that (see just below), but I get the same number of rows back if I haven't filtered anything... uff. SELECT * FROM lessons_master_001 my1 WHERE NOT EXISTS ( SELECT 0 FROM lessons_master_001 my2 WHERE my1.student_id = my2.`student_id` AND my1.teacher_id = my2.teacher_id AND my1.`student_payment_id`= my2.`student_payment_id`AND CONCAT(CAST(MONTH(DATE_ADD(my1.Lesson_Booking_Date, INTERVAL -1 MONTH))AS CHAR(20)),CAST(YEAR(DATE_ADD(my1.Lesson_Booking_Date, INTERVAL -1 MONTH))AS CHAR(20))) = CONCAT(CAST(MONTH(my2.`Lesson_Booking_Date`)AS CHAR(20)),CAST(YEAR(my2.`Lesson_Booking_Date`)AS CHAR(20))) ) My logic is like this so I take everything from the view lessons_master_001 and give alias my1 and in the NOT EXISTS clause I am giving to the same dataset alias my2, then join those ID's that are also used in view lessons_master_001 and then try to connect previous month from data set my1 with current month from data set my2. I am using DATE_ADD function to subtract month from current date and practically get date - 1 month. I would really appreciate any help you will provide, cause I lost 2 days already on it with no progress in front. Thank you in advance.
  10. Greetings all, So I'm starting to play around with incorporating databases into dynamic pages and I've come across an issue that was only vaguely covered during my PHP course in college. The script below works great except that it needs a natsort and I'm not sure how to do a natsort and still make the while loop work. I'm not even sure how to go about writing it. The script queries the database for the video names, video descriptions and then turns them into links (with a little css and java help). But after video 9 it starts to order incorrectly. It goes ...1, 10, 11, 12, 2, 3, 4, 5.... you get the idea, needs a natsort. I just don't have a clue how to go about doing that and keeping the while loop working. I tried a couple things but I'm just not figuring this out. <?php require ('masters/connect.php'); // Define the query: $q = "SELECT * FROM videofiles WHERE folder='" . $sect . "' ORDER BY vidname"; $r = @mysqli_query ($connect, $q); // Count the number of returned rows: $num = mysqli_num_rows($r); if ($num > 0) { // Table header: echo '<h1>Section Lessons</h1>'; echo '<table id="link-table">'; // Set up array to remove beginning url from database section names. $sectpattern = $sect; $patterns = array(); $patterns[0] = '/videos/'; $patterns[1] = '/\//'; $patterns[2] = '/' . $sectpattern . '/'; $patterns[3] = '/\\.[^.\\s]{3,4}$/'; $replacements = array(); $replacements[0] = 'Lesson '; // Fetch and print all the records: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { echo '<tr> <td>' . "<a href=\"javascript:create_window('".$row['vidname']."',640,360)\">Click Here</a>" . '</td> <td align="left"> <div id="tabledataimage1"> <img src="'. $row['vidimage'] .'" width="100"/> </div> <div id="tabledatatitle1"> <h4>' . preg_replace($patterns, $replacements, $row['vidname']) . '</h4> </div> <div id="tabledatadesc1"> ' . $row['viddesc'] . ' </div> </td> </tr>'; } echo '</table>'; mysqli_free_result ($r); } else { // Inform that no entries were returned from the query. echo '<p>There are currently no videos in this section.</p>'; } // Close database connection: mysqli_close($connect); ?> As always any help is greatly appreciated. I'm having a lot of fun learning PHP but I still have a long ways to go. Best Regards, Nightasy
  11. hi, ive just started learning php and sql yesterday. im building a timesheets webpage for employees i want to know how to join the 'totalhours' to "totalminutes' and then put it in the query as one value? eg the databse will store 5.25 or 3.75 etc. the employees will type an hour (eg 5 or 3 ) and then click a radio button that says 15mins or 45mins here is the code so far: PHP $sql="INSERT INTO Persons (notes, starttime, date, finishtime, totalhours, company, breaktime) VALUES ('$_POST[notes]','$_POST[starttime]','$_POST[date]','$_POST[finishtime]','$_POST[totalhours]', '$_POST[comp]','$_POST[breaktime]')"; HTML <form action="submittimesheet.php" method="post"> company<input type="text" name="comp"><br> date<input type="date" name="date"><br> start time <input type="time" name="starttime"> finish time <input type="time" name="finishtime"><br> total break time<input type="text" name="breaktime"><br> total hours worked<input type="text" name="totalhours">(number from 1-10)<br> total minutes worked: <br> <input type="radio" value="0" name="totalminutes">0<br> <input type="radio" value="25" name="totalminutes">15<br> <input type="radio" value="50" name="totalminutes">30<br> <input type="radio" value="75" name="totalminutes">45<br> notes<input type="text" name="notes" style="height: 50px;"><br> <input type="submit">
  12. Hi All, Wondering in anyone can assist me with a couple of queries which have cropped up in a project. The project is a database of people and their attendance of training courses. There are a few tables... Users (with UserID and Username) Teachers (with TeacherID and TeacherName) Courses (with CourseID, CourseName, CourseDate and TeacherID) - this one relates to which teacher took which course Attendances (with UserID and CourseID) - this one relates which user attended which course What the client is after is firstly selecting all the users who have NOT attended a specific teachers' courses. In other words, if the have been on a course with the specified teacher, they will not be shown. Secondly, the client wants the same query as the first but also limiting it to the last 6 months. In other words, selecting all the users who have NOT attended a specific teachers' courses within the last six months. This one has got me a bit baffled so any assistance would be appreciated. Rik
  13. hi, i need some help, in mysql query the output show as below :- 020000000000000000000790715035426 FIRSTNAME LASTNAME 800 000000000015900000000000013500000000000121700 but when i do <?php $data1 = mysql_query("SELECT * FROM details_view WHERE hashtotal = '$id'") or die(mysql_error()); while($info1 = mysql_fetch_array( $data1 )) { print $info1['details']; } ; ?> the output is :- 020000000000000000000790715035426 FIRSTNAME LASTNAME 800 000000000015900000000000013500000000000121700 How to make the php query same character length as mysql query? thank you.
  14. Below is my query: <?php if (isset($_POST['search_all_submit'])){ $search_all = strtolower($_POST['search_all']); echo "<table id='qbook'>"; echo "<tr>"; echo "<td> CID </td>"; echo "<td> Company </td>"; echo "<td> Property </td>"; echo "<td> Contact </td>"; echo "</tr>"; $sql = " SELECT contract.*, customer.*, contact.* FROM customer INNER JOIN contract ON customer.customer_id = contract.customer_id INNER JOIN contact ON customer.customer_id = contact.customer_id WHERE customer.company_name like '%".$search_all."%' or customer.billing_address like '%".$search_all."%' or contract.prop_name like '%".$search_all."%' or contract.prop_address like '%".$search_all."%' or contact.contact_fname like '%".$search_all."%' or contact.contact_lname like '%".$search_all."%' "; $results = mysql_query($sql)or die(mysql_error()); while ($row = mysql_fetch_array($results)){ $company_name = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['company_name']))); $billing_address = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['billing_address']))); $prop_name = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['prop_name']))); $prop_address = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['prop_address']))); $fname = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['contact_fname']))); $lname = implode('<span class="high">'.$search_all.'</span>',explode($search_all,strtolower($row['contact_lname']))); $CID = $row['CID']; echo "<tr>"; echo "<td> $CID </td>"; echo "<td> $company_name <br /> $billing_address </td>"; echo "<td> $prop_name <br /> $prop_address </td>"; echo "<td> $fname $lname</td>"; echo "</tr>"; } echo "</table>"; } ?> The query above gives me results like: 10008 | jw property management | creekside crossing | mike pudelek | 4816 green bay rd | 9219 66th ave | 10008 | jw property management | creekside crossing | sam johnson | 4816 green bay rd | 9219 66th ave | 10008 | jw property management | creekside crossing | dean zierk | 4816 green bay rd | 9219 66th ave | What I would like to see is: 10008 | jw property management | creekside crossing | dean zierk | 4816 green bay rd | 9219 66th ave | mike pudelek | sam johnson I am pretty sure that I need to use some type of GROUP CONCAT and possibly a GROUP BY. However all of my attemps have failed. Any help would be appreciated.
  15. Insert function not working like the select functions are.. :~ I have a functions file that contains a number of mysqli_query query's that other php pages successfully call, including the page in question. For round numbers I have 10 functions total. Of the 10, 9 are select query's, 1 is an insert. All of the select query's work including 2 on the page in question. These 2 query's populate 2 drop down menus in a form. When I submit the form I am $_POST ing all the fields to another PHP file that parses the data, calls the insert function -> sends the values, then sends an e-mail using PHPMailer.. When I call the Insert query (submit the form), I am returned "Error updating databaseNo database selected" Error. All of the php pages have an include statement on top pointing to a connection file. IF I put a DB connection string inside the insert function, per below, the insert function works when called.. There's gotta be something basic I'm missing with how I have my stuff setup.. Does anybody have advice? Or I guess I could have everything on one page / file.... mysql_connect("server", "user", "pass") or die('Can\'t connect because:' .mysql_error()); mysql_select_db ("database"); thanx
  16. I am trying to show two different options, depending on if the table is empty or not. It's a form to post images of artists. The user should be able to add images to existing artist, but if not artist has yet been added, then the option to add a new should be showed instead. I haven't added any artist to the DB yet, and therefor is empty, yet this code always shows the empty dropdown menu and never the text box. What is the best way to check if a query is empty or not to use in an if-statement? $query = "SELECT artist_id, artist_name FROM content_artists ORDER BY artist_name ASC"; $result = $mysqli->query($query); if ($result) { echo " <td>Pick from existing artits:</td> <td>"; echo "<select name='ac_artist_id'>"; while ($row = $result->fetch_array(MYSQLI_ASSOC)) { echo "<option value='" . $row['artist_id'] . "'>" . $row['artist_name'] . "</option>"; } echo "</select></td>"; } else { echo " <td>Name of artist:</td> <td><input type=\"text\" name=\"artist_name\"></td> "; }
  17. Query: SELECT UMTS_napetude_cell.parent, UMTS_napetude_nodeb.idnap FROM UMTS_napetude_cell LEFT JOIN UMTS_napetude_nodeb ON UMTS_napetude_cell.parent IS NOT LIKE CONCAT('%',UMTS_napetude_nodeb.idnap,'%') WHERE UMTS_napetude_cell.parent IS NOT NULL Error: Thanks in advanced.
  18. Hey all. First I want to say that I'm very amateur when it comes to coding. Most of what I know has been self-taught so I don't have any formal education. My coding vocabulary is awful, but generally when I build code I understand what it's doing in laymen terms (ex. it's pulling data from the "users" row in a table and is displaying that data). Anyway...that's my disclaimer to ask you to be easy on me. So now to my actual issue. I've built a page where logged in users can share photos with their friends. I successfully built this without any issues. Now I want friends to be able to add comments to the photos. Not so easy. Problem is I have two tables built. One for the sharing of the photos the other for the comments. Here are how the tables are built out: Photo Table id | username | initiator | file | gallery | date_time Comment Table id | comment | user | file | date_time Initially I had two queries. Both use a "fetch" array in order to grab and then display specific info in a specific order only for specific users. This was almost working but whichever query came first would only display one result. The query that came after would display all the appropriate results which is what I wanted out of both queries. On another forum I was told that I needed to "join" or "union" the two queries together. Problem is that when I attempt to do that I get a single dead image, no comments other than the default stuff that is already entered in the PHP code and the error: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given... Here is the actual query and code: //WHERE I GATHER COMMENT & PHOTO DATA $sql = "SELECT comment, user, file, date_time FROM comment UNION ALL SELECT DISTINCT initiator, file, gallery FROM photo WHERE username='$log_username' OR initiator='$log_username' ORDER BY date_time DESC"; $query = mysqli_query($db_conx, $sql); while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) { $c = $row["comment"]; $us = $row["user"]; $pf = $row["file"]; $time = $row["date_time"]; $u = $row["initiator"]; $file = $row["file"]; $gallery = $row["gallery"]; $image = 'user/'.$u.'/'.$file; } //WHERE I DISPLAY THE PHOTO DATA $imagelist .= ' <img height="200" onclick="this.height=500;" ondblclick="this.height=200;" src="'.$image.'" alt="'.$u.'" /><br /> Added to <a href="user.php?u='.$u.'"><b>'.$u.''s</b></a> '.$gallery.' gallery<br /><br /> <form action="php_parsers/photocomments_system.php" enctype="multipart/form-data" method="post"> <input type="text" name="comment"> <input type="hidden" name="photo_file" value="'.$file.'"> <input type="submit" class="submit" value=" Submit Comment " /> </form><br /><p style="border-bottom: 1px dotted #A0A0A0;"></p>'; //WHERE I DISPLAY THE PHOTO COMMENTS AND DICTATE WHAT COMMENT SHOWS WITH WHAT PHOTO if ($pf == $file) { $imagelist .='<p style="background-color:#E0E0E0;"> <b>'.$us.'</b>: '.$c.' | '.$time.'</p> <br /><br /><hr/>'; } For the HTML portion this is where it actually gets displayed: <div id="page Middle"><?php echo $imagelist; ?></div> Anyway, I'm assuming there is something wrong with my query and that's why I'm getting the error. Problem is I'm not sure what is wrong with the query. If there is any easier way to do this and I was doing something wrong with the two separate queries that could easily be resolved I can show you how I built that as well. I would continue on the other forum with the guy that was helping me but he was a little bit too technical for me to understand his suggestions. Anyway, any help you could give would be GREATLY appreciated. Thanks!
  19. I have the following query that gives me the result i want. In a nutshell it searches two columns to find the max value in each of these two columns and returns the sum of these two values. When i try to pass it to a variable in php it doesn't seem to work. I want to be able to pass the sum in a variable so i can use the variable later into an IF Condition. For example: if ($scoremax >= '160') { code here } Here is my query: select (max(scoreioa) + max(scoreioa2)) from result where username='username' and here is the php code: $maxscore = mysql_query("select (max(scoreioa) + max(scoreioa2)) from result where username='username'"); mysql_data_seek($maxscore, $scoremax); $row = mysql_fetch_row($maxscore); $scoremax = $row[0];
  20. hey, this should echo all of the results from the query, right? in the database there is more than 1 fields to echo, but it only echos 1, whats wrong with it? $getid = mysql_query("SELECT * FROM $tbl_name WHERE userid='$id'", $connect); $idresults= mysql_fetch_array($getid); while($idresults= mysql_fetch_array($getid)){ echo $idresults['frienduserid']; }
  21. hello I have a query which is long, but the main section I have a question about is GROUP BY id ORDER BY id DESC LIMIT 10 this works ok and gives me the first 10 records in descending order, so it gets oldest to newest what do I need to do, to keep the query (first 10 records) but order by newest to oldest can anyone help me, I've searched high and low, and tried lots of ideas, but cannot get it to work right thanxs
  22. I have 4 studies that I need to display on a page. I was printing them in order, but I would like to make a partition that clearly distinguishes each section, studyID and studyName. Here is the code thus far: $sql = 'SELECT * FROM tbl_studies'; $list = mysqli_query($dbcon, $sql); $numRecords = mysqli_num_rows($list); for ($i = 1; $i < $numRecords ; $i++){ $sql1 = 'SELECT * FROM tbl_studies JOIN tbl_childinformation ON tbl_studies.studyID = tbl_childinformation.studyID JOIN tbl_parentinformation ON tbl_childinformation.parentID = tbl_parentinformation.parentID'; $list1 = mysqli_query($dbcon, $sql1); $record1 = mysqli_fetch_assoc($list1); echo "<center>----------------------------------------------------------------------<br>"; echo "<center>" . $record1['studyID'] . ' ' . $record1['studyName'] . "</center>"; echo "----------------------------------------------------------------------</center><br />"; $sql = "SELECT * from tbl_studies JOIN tbl_childinformation ON tbl_studies.studyID = tbl_childinformation.studyID JOIN tbl_parentinformation ON tbl_childinformation.parentID = tbl_parentinformation.parentID WHERE tbl_childinformation.studyID = '$record1[studyID]'"; $list = mysqli_query($dbcon, $sql); while($record = mysqli_fetch_assoc($list)){ $newbirthdate = date('m/d/Y', strtotime($record['dateOfBirth'])); $newstudydate = date('m/d/Y', strtotime($record['dateOfStudy'])); echo $record['studyID'] . ' ' . $record['studyName'] . '<br>'; echo "<p class = \"smallerfont\"><em>ID:</em> " . $record['childID'] . "<p class = \"smallerfont\"><em>Name:</em> " . $record['childFirstName'] . ' ' . $record['childLastName'] . "<p class = \"smallerfont\"><em>Date of Birth:</em> " . $newbirthdate . "<p class=\"smallerfont\"><em>Twin?:</em> " . ($record['twin'] == 1 ? 'Yes' : 'No') . "<p class = \"smallerfont\"><em>Medical Conditions:</em> " . $record['medicalConditions'] . "<p class = \"smallerfont\"><em>StudyID:</em> " . $record['studyID'] . "<p class=\"smallerfont\"><em>Date of Study:</em> " . $newstudydate . '<br /><br />'; echo "<div id=\"parentblock\">"; echo "<a id= \"parentlink\" href=\"parentinformationlink.php?pid=" . $record['parentID'] . "\"> Link to " . $record['parentOneFirstName'] . ' ' . $record['parentOneLastName'] . (empty($record['parentTwoFirstName']) ? '</a>':' and ' . $record['parentTwoFirstName'] . ' ' . $record['parentTwoLastName']) . "</a>"; echo "</div>"; } } So basically, I figured I could count the number of studies there are after querying the tbl_studies, and then for a for loop, and only print the children that have matching studyID's. Works great for the first loop, but I need to reference the 2nd record, and so on. Is there a way to achieve this in php? Any advice is greatly appreciated!
  23. Heya everyone, Still working on learning PHP in my college course and I ran into another problem. I'm kind of stumped because the assignment gave me some extra code, told me exactly where to place it and it is not working. It's kind of frustrating lol. Anyhow, perhaps someone could explain why this is not working. This is the code they told me to put into my script. Instructions: Add the following code to check to see if the guest already exists in the database. Place the code immediately above the INSERT query as part of your validation routines. //Check to see if guest already exists in the database $query = "SELECT * from guests WHERE fname='$fname' AND lname='$lname' AND email='$email'"; if ($result = mysqli_query($connect,$query) or die(mysqli_error($connect))) { echo "You have already signed my guestbook. Thanks!"; } else { YOUR EXISTING INSERT QUERY AND ECHO STATEMENTS DISPLAYING THE QUERY RESULTS ARE HERE } So I did that and here is what it looks like: <?php //Set variable for page title prior to loading header which needs the page title variable. $pagetitle = 'Student, PHP'; //Add in header. include ('includes/header.php'); //Requires the database connection script. require ('includes/connect.php'); ?> <!-- Sticky form displays --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <fieldset> <legend>Please sign my guest book!</legend> <label for="fname">First: </label><input type="text" name="fname" size="25" maxlength="25" value="<?php if(isset($_POST['fname'])) echo $_POST['fname'];?>"/> <br/> <label for="lname">Last: </label><input type="text" name="lname" size="25" maxlength="25" value="<?php if(isset($_POST['lname'])) echo $_POST['lname'];?>"/> <br/> <label for="email">Email: </label><input type="text" name="email" size="25" maxlength="50" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>"/> <br/> <label for="password">Password: </label><input type="password" name="password" size="10" maxlength="40" value="<?php if(isset($_POST['password'])) echo $_POST['password'];?>"/> <br/> <label for="confirmpass">Confirm Password: </label><input type="password" name="confirmpass" size="10" maxlength="40" value="<?php if(isset($_POST['confirmpass'])) echo $_POST['confirmpass'];?>"/> <br /> <p><b>Comments</b></p> <textarea name="comment" cols="40" rows="10" maxlength="255"><?php if(isset($_POST['comment'])) echo $_POST['comment'];?></textarea> <br/> <input type="reset" value="Reset"/> <input type="submit" name="submit" value="Submit" /> <br/> </fieldset> </form> <?php //Your PHP code to process the submitted form goes here. if ($_SERVER['REQUEST_METHOD'] == 'POST'){ // Perform Validation if (!empty($_POST['fname'])){ if (!empty($_POST['lname'])){ if (!empty($_POST['email'])){ $email = $_POST['email']; if (strstr($email, '@', true)){ if (!empty($_POST['password'])){ if (!empty($_POST['confirmpass'])){ if ($_POST['password'] == $_POST['confirmpass']){ if (!empty($_POST['comment'])){ $comment = mysqli_real_escape_string($connect, trim($_POST['comment'])); } else if (empty($_POST['comment'])){ $comment = NULL; } // assign and trim variables. $fname = mysqli_real_escape_string($connect, trim($_POST['fname'])); $lname = mysqli_real_escape_string($connect, trim($_POST['lname'])); $email = mysqli_real_escape_string($connect, trim($_POST['email'])); $password = mysqli_real_escape_string($connect, trim($_POST['password'])); // Display connection error if any. if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } //Check to see if guest already exists in the database $query = "SELECT * from guests WHERE fname='$fname' AND lname='$lname' AND email='$email'"; if ($result = mysqli_query($connect,$query) or die(mysqli_error($connect))) { echo "You have already signed my guestbook. Thanks!"; } else { // Enter user input into database $query = "INSERT INTO guests (fname, lname, email, password, comment) VALUES ('$fname','$lname','$email','$password','$comment')"; // If error kill script and display error. if (!mysqli_query($connect,$query)) { die('Error: ' . mysqli_error($connect)); } // Display success messaage. echo "<h1><p class='message'>Greetings $fname</p></h1>"; echo "<p class='message'>Thank you for signing my guest book!</p>"; // Close database connection. mysqli_close($connect); } // If validation fails display. } else if ($_POST['password'] != $_POST['confirmpass']){ echo '<p class="message">Your password confirmation does not match.</p>';} } else { echo '<p class="message">Please confirm your password.</p>';} } else { echo '<p class="message">Please enter a password.</p>';} } else { echo '<p class="message">Please enter a valid email address.</p>';} } else { echo '<p class="message">Please enter an email address.</p>';} } else { echo '<p class="message">Please enter your last name.</p>';} } else { echo '<p class="message">Please enter your first name.</p>';} } //Add in footer. include ('includes/footer.php'); ?> At the far right of my little pyramid scheme here you can see that I put the required code where it asked me to in the instructions. The problem I have now is that I can not longer enter any new users into the database, it always tells me "You have already signed my Guestbook." If anyone can help me out here I would really appreciate it. I just don't understand exactly what the problem is. As always thanks just for looking. Best Regards, Nightasy
  24. I have a pretty beginner's question, but cant seem to get this right with what i try. I had the same problem with using LIKE and OR with multiple fields and queries. essentially i just want to ORDER BY using multiple fields i have in the DB. my query is something like this $query = "SELECT * FROM content WHERE rating > 7 ORDER BY `votes` DESC, `release_date` DESC "; now i understand with LIKE and OR you must separate arguments with (), but with ORDER BY i am not using any AND / OR so i though a comma should be sufficient. Yet, i can never seem to get this work properly. any suggestions to get both fields to ORDER BY ? thanks guys
  25. Hello, I am trying to run MySQL query that will take a bunch of letters and do a couple things. First: If they enter "drea" then I want to search for all words in my DB that contain those letters and only those letters. So the result will be" read dear ear red etc..... Next I want to run another query that would have Exactly the letters in the word. So the same query "drea" would only come up with: read dear Any help would be greatly appreciated! Thanks!
×
×
  • 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.