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. I would like to run a simple query one time without user input. Can I just use a query? Or is there benefit to doing it another way?
  2. I have other things that work, but for some reason when trying this one is does not want to put the results into the table. Here is my code: echo "<table border='1px' cellpadding='5' style='border:3px solid black; text-align: center;'> <tr> <th style='border:3px solid black;'>Rep</th> <th style='border:3px solid black;'>Pmts Collected</th> </tr>"; while ($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)) { [code] echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>"; } echo "</table>"; sqlsrv_free_stmt ($result); sqlsrv_close( $connection); ?> [/code] When I view source of the page this part is not in there: echo "<tr> <td>{$row['Rep']}</td> <td>{$row['Num_Payments']}</td> </tr>"; So I know I have the while part of the code wrong in the table somehow but not sure how to make it work. Let me know if I need to provide more information. Thanks in advance!
  3. <h1>View Log</h1> <?php $timezone = "America/Chicago"; date_default_timezone_set($timezone); $today = date("Y-m-d"); ?> <?php $serverName = 'Server\SQLEXPRESS'; $connectionInfo = array('Database'=>'database', 'UID'=>'username', 'PWD'=>'password','ReturnDatesAsStrings'=>true,); $connection = sqlsrv_connect($serverName, $connectionInfo); $query = ' SELECT ForteID FROM database.dbo.Reps ORDER By ForteID'; $result = sqlsrv_query($connection,$query); // Move the data to a simple array to simplify presentation code. $resultAsArray = array(); while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) { $resultAsArray = $row; } ?> <form method="get" action="getlog.php"> <select> <?php foreach ($resultAsArray as $row): ?> <option value="<?php= $row['ForteID'] ?>"><?php= $row['ForteID'] ?></option> <?php endforeach; ?> </select> <BR> <table> <tr> <td>Start Date:</td> <td><input name="start_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> <tr> <td>End Date:</td> <td><input name="end_date" type="date" value="<?php echo $today;?>" autocomplete="off" required="required"></td> </tr> </table> <br> <input type="submit" name="getLog" value="Get Log"><br><br> <input type="button" value="Back to Form" onclick="window.location.href='index.php';"> <br> </form> </html> My result for the drop down box is nothing. I believe something is wrong with the while ( $row = sqlsrv_fetch_array( $result, SQLSRV_FETCH_ASSOC )) Thanks in advance for the help.
  4. Hi, I know this is a very basic query but most of the tutorials etc. I can find seem to focus on querying multiple tables rather than one table. I want to filter the data from one table (Mutation) by three variables (prot_name, no_changes and amyloid) (all in this one table). In my main HTML page I have the form: <p><b>Advanced Search:</b>search for subgroups of mutations associated with a particular protein</p> <form action= "adv_mutationsearch.php" method='post'> <select name="result1"> <option value="alpha synuclein">alpha synclein</option> <option value="amyloid precursor protein">amyloid precursor protein</option> <option value="apolipoprotein A-1 precursor">apolipoprotein A-1 precursor</option> <option value="apolipoprotein A-1V precursor">apolipoprotein A-1V precursor</option> </select> <p><b>AND</b></p> <select name="result3"> <option value="amyloid">Amyloid</option> <option value="amorphous">Amorphous</option> <option value="non-amyloid">Non-amyloid</option> <option value="oligomers">Oligomers</option> <option value="undetermined">Undetermined</option> </select> <p><b>AND</b></p> <select name="result2"> <option value="single">Single</option> <option value="double">Double</option> <option value="multiple">Multiple</option> <option value="wild">Wild (original sequence)</option> </select> <br> <br> <input type='submit' value = 'filter'> </form> in my php file: <html><head> <link rel="stylesheet" type="text/css" href="tabs.css" media="screen" /> <title>Amyprot Table Viewer</title></head><body> <?php $db_host = '********'; $db_user = '********'; $db_pwd = '*********'; $database = 'amyprotdb'; $table = 'Mutation'; //receiving results from form submission and allocating to variables for query $query1 = $_POST['result1']; $query2 = $_POST['result2']; $query3 = $_POST['result3']; // connect to database if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); // query for sorting mutations by protein, number of changes and amyloidogenicity and printing result $result = mysql_query("SELECT * FROM {$table} WHERE prot_name_id={$query1} AND no_changes={$query2} AND amyloid={$query3}"); //to show results in table the current problem lies with the code below, the above code dows not show errors so need to undertsand the below sections. or change it to ordinary print out. $fields_num = mysql_num_fields($result); echo "<h1>Table: {$table}</h1>"; //echo "<table border='1'><tr>"; echo '<table cellpadding="0" cellspacing="1" class="db-table">'; // printing table headers for($i=0; $i<$fields_num; $i++) { $field = mysql_fetch_field($result); echo "<td>{$field->name}</td>"; } echo "</tr>\n"; // printing table rows while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) echo "<td>$cell</td>"; echo "</tr>\n"; } //mysql_free_result($result); ?> <div class="search"> <p>Return to database search page <a href="database.php"><span>Search</span></a></p> <p>Return to full mutations table <a href="mutationtable.php"><span>Mutation table</span></a></p> </div> </body></html> The error I get states that $result (when I am trying to print the table of results) is null meaning the whol post submission hasnt worked. I am an early learner as you can see, I have tried multiple ways to do this.. The set up above has been pared right back to the basics as I tried to clean up my code to see where the fault lay and now I am stuck. Thanks in advance x
  5. heres my code: $sql=" INSERT INTO `a8392424_pets`.`users` ( `user_id` , `user_name` , `user_pass` , `user_email` , `user_date` , `user_level` , `posts` , `married` , `cash` , `tokens` ) VALUES ( NULL, '" . mysql_real_escape_string($_POST['user_name']) . "', '" . sha1($_POST['user_pass']) . "', '" . mysql_real_escape_string($_POST['user_email']) . "', NOW(),'0', 'noone', '10000', '10')"; $result = mysql_query($sql); if(!$result) { //something went wrong, display the error echo 'Something went wrong while registering. Please try again later.'; //echo mysql_error(); //debugging purposes, uncomment when needed } When I execute it, using my signup form, the query fails. my connection to database is GOOD.
  6. I am passing user inputs from a page called add_product.php. There is a drop down menu that CONCATs two table fields to form one name ($category). After passing $category to the product_created.php page, I can break this back down into the two respective fields using explode() on but how do I create variable out of the results? Here is the snippet from add_product.php <?php //Grab the Product Category name and Bucket name from productcategory and bucket tables in DB $qry=mysql_query("SELECT CONCAT(bucket.b_name, ' : ', productcategory.name) AS category FROM productcategory, bucket, product WHERE product.category_id = productcategory.id AND productcategory.bucket_id = bucket.id", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } ?> <p>Category: <select name="category" id="category"> <?php //take the responses from the query above and show then in a drop down menu while($row=mysql_fetch_array($qry)) { echo $category = "<option value='".$row['category']."'>".$row['category']."</option>"; } ?> </select> I then pass that to product_created.php and this is what I have so far and where I am stuck: //This gets all the other information from the form $category=$_POST['category']; // Explode category variable to get bucket.b_name and productcategory.name list($b_name, $pc_name) = explode(":", $category); echo $b_name.'<br/>'; // bucket.b_name echo $pc_name.'<br/>'; // productcategory.name //the above code works and prints the separate category names onscreen $categories = array($b_name,$pc_name); print "The product category name is $pc_name"; //test two: this code works and prints just the productcategory name //Define the query to grab the product category id where pc_name equals the product category name $sql = "SELECT id FROM productcategory WHERE name = '$pc_name'"; //submit the query and capture the result $result = mysql_query($sql) or die(mysql_error()); echo $result; //find out how many rows were retrieved $numRows = mysql_num_rows($result); //current result is 0 and should be 1 if successful //this is my attempt to convert the productcategory id into a variable that can be passed back into the DB $sql_q = "SELECT id FROM productcategory WHERE name = '$pc_name'" or die(mysql_error()); $sql = mysql_fetch_array($sql_q); //above sets the category_id array //example usage: $sql['mysql_col_name'] echo $sql['category_id']; //the above prints the category_id foreach ($sql as $category_id) { //echo $category_id.'<br/>'; } //Define query to add product to DB $qry=mysql_query("INSERT INTO product(name,category_id,slug,old_price,price,description,video_url,status,date_posted)VALUES('$name','$category_id','$slug','$o_price','$price','$desc','$video','$status','$date')", $con); if(!$qry) { die("Query Failed: ". mysql_error()); } else { echo "<br/>"; echo "Product Added Successfully"; echo "<br/>"; } I know some of this is redundant but I am trying to teach myself how to solve this and this was the best way for me to learn. I feel like I am really close, but that I have gone round and round at this point and have just confused myself. I understand that there may be other issues with my code as it is written, but I really need to focus on resolving this first. Any help, advise, teaching, would be most appreciated.
  7. Hello, I am doing a kind of financial calculator which gives you results about the best alternatives to choose from. I do a sql query to the table having the banks data. After that i create a bunch of variables in php and echo the results. These variables are math operations consisting in sql results variables and user input variables. I know how to order sql results, but the problem is that my criteria of sorting is from the php variables created later (which consist of math oparations between sql and user input variables). I have tried sorting it by sql rows....but the dynamic php variables created later are sometimes negatively related to the sql data....so the result does not always get the same. I have an idea like putting the dynamic php variables in an array/arrays and than sorting them according to one of the php variables. But i have no idea how it can be done. Here is a partial code, just to give you an idea of what i mean. <form method="post" action="calc2.php" /> <input name="ss" class="highlight"/> <input class="highlight" name="nn" size="5" /> </form> <?php if (isset($_POST['ss']) && $_POST['nn']>5) { $target = $_POST['ss']; $result = mysql_query("SELECT * FROM list1 WHERE minimum <= {$target} ORDER BY i_rate DESC LIMIT {$number_result}"); if (mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)) { $s = $target-$support+$pu+$pv; // according to this variable i want to sort the results, and $pu, $pv are created from user input, which i don't have it here, $traget is sql output. $s is a mix. } } } ?> PLS HEEELP, i have searched everywhere for this and cennot find nothing about exactly what i want.
  8. Ok, i think this is the best place for this question. I have the following problem that no matter what i do the number doesn't add to the sql variable. $i=interest rate, which is a row in sql database, i need to add 1 to it. The result is 1. Which should have been for example 1.01 if $i=1. Here is the code: $result1 = mysql_query("SELECT interest_rate FROM list1") or die(mysql_error()); $row1 = mysql_fetch_array($result1); $i = $row1['interest_rate']; echo $i . "<br/>"; echo $i+1 . "<br/>"; On echo $i i get the row values. On $i+1 i get only 1 in a column repeated vertically. WHY?? PLSSSSS help!!!!
  9. Hey there, Hoping someone can help me. I am trying to create a page on a wordpress site that will enable users to select 4 seperate fields from 4 drop down lists, hit a submit button and then be presented with search results from a MYSQL query based on their selections from the drop down list. I am a complete noob at php and MYSQL having not touched either since Uni. Please help out if you can. Here is the code. I have omitted the database connection details for obvious reasons. //Select City from Users table $queryCity = "SELECT City FROM Users"; $resultCity = mysql_query($queryCity) or die(mysql_error()); //Select AO from Users table $queryAO = "SELECT AO FROM Users"; $resultAO = mysql_query($queryAO) or die(mysql_error()); //Select Job from Users table $queryJob = "SELECT Job FROM Users"; $resultJob = mysql_query($queryJob) or die(mysql_error()); //Select Skills from Users table $querySkills = "SELECT Skills FROM Users"; $resultSkills = mysql_query($querySkills) or die(mysql_error()); //Create City dropdown list object $dropdownCity = "<select name='selectCity'>"; while($rowCity = mysql_fetch_assoc($resultCity)) { $dropdownCity .= "\r\n<option value='{$rowCity['City']}'>{$rowCity['City']}</option>"; } $dropdownCity .= "\r\n</select>"; //Create AO dropdown list object $dropdownAO = "<select name='selectAO'>"; while($rowAO = mysql_fetch_assoc($resultAO)) { $dropdownAO .= "\r\n<option value='{$rowAO['AO']}'>{$rowAO['AO']}</option>"; } $dropdownAO .= "\r\n</select>"; //Create Job dropdown list object $dropdownJob = "<select name='selectJob'>"; while($rowJob = mysql_fetch_assoc($resultJob)) { $dropdownJob .= "\r\n<option value='{$rowJob['Job']}'>{$rowJob['Job']}</option>"; } $dropdownJob .= "\r\n</select>"; //Create Skills dropdown list object $dropdownSkills = "<select name='selectSkills'>"; while($rowSkills = mysql_fetch_assoc($resultSkills)) { $dropdownSkills .= "\r\n<option value='{$rowSkills['Skills']}'>{$rowSkills['Skills']}</option>"; } $dropdownSkills .= "\r\n</select>"; //Print the drop downlists on the page echo "Please choose from the following fields below:"; echo "Location &nbsp&nbsp&nbsp"; echo $dropdownCity; echo "AO Level &nbsp&nbsp&nbsp"; echo $dropdownAO; echo "Occupation &nbsp&nbsp&nbsp"; echo $dropdownJob; echo "Skills &nbsp&nbsp&nbsp"; echo $dropdownSkills; ?> <form method="post" action="mypage.php"> <input type="submit" value="submit" name="Submit"> <?php //This code is for retrieving the results of the drop down selections after the submit button is clicked $selectionCity = $_POST["selectSkills"]; $selectionJob = $_POST["selectJob"]; //SQL query from retrieved results //SQL query from retrieved results $sqlresults = "SELECT * FROM Users WHERE City='"$selectionCity"' AND Job='"$selectionJob"'"; $sqlpost = mysql_query($sqlresults) or die(mysql_error()); echo $sqlpost; ?> I know the page looks horrible, trying to tackle one issue at a time and get this functional. Thanks for any and all help.
  10. I have never done any calculations with sql query, so I have no idea how to do this so please help. well i have two tables acc_tbl and ledger_tbl ( screenshots ) i need to find the the difference between total debit and total credit of that particular ledger debit (Dr) and credit(Cr) everything in screenshot. All i know was to join the table and select all thr columns available.
  11. Hello. I'm a newbie so sorry if this isn't the best forum to post my problem. I am using a MySQL and PHP to create a web app. I have authentication, and I can register users. I also have a form that users provide information and it is successfully inserting data into a table in my database. I will use fictional fields for my database table called meal_info: username dateStartedDiet numberMealsPerDay costPerMeal Problem: Select user-specific data from the MySQL database, using Session username to select only the current user's data, then display it and do some calculations. Here is thecode at the top, and I am fairly sure it's working: session_start(); //execute commone code require("common.php"); //includes code to connect to database, etc. if(empty($_SESSION['user'])) { // If they are not, we redirect them to the login page. header("Location: login.php"); // Remember that this die statement is absolutely critical. Without it, // people can view your members-only content without logging in. die("Redirecting to login.php"); } Here is the part of the code that has to do with displaying user data: $userID = $_SESSION['user']['username']; //create a variable that is the session username which is identical to the field in our MySQL table $query = "SELECT * FROM meal_info WHERE username = $userID"; //our SELECT statement $result = db->query($query); //execute the query $row_count = $result->num_rows;//count the rows in the table and place in variable to use in incremental loop code for ($i = 0; $i < $row_count; $i++) : $row = $result->fetch_assoc(); //for each row in the table, fetch and create and array $dateStart = $row['dateStartedDiet']; $numberMeals = $row['numberMealsPerDay']; $costMeal = $row['costPerMeal']; echo $dateStart; echo $numberMeals; echo $costMeal;
  12. So I am working with a script that allows load more scrolling, much like youtube's comments section. The script I found uses mysqli and I am using PDO. So I need a bit of help converting some code below. Origional mysqli $results = mysqli_query($connecDB,"SELECT COUNT(*) FROM paginate"); $get_total_rows = mysqli_fetch_array($results); //total records //break total records into pages $total_pages = ceil($get_total_rows[0]/$item_per_page); My PDO code $results = DB::getInstance()->query("SELECT COUNT(*) FROM guestbook"); $get_total_rows = $results->results(); //break total records into pages $total_pages = ceil($get_total_rows[0]/$item_per_page); With the code above, I get the following error. "Object of class stdClass could not be converted to int"
×
×
  • 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.