MySQL Results To Return Only One Value
For example, I have a column that has three different values, 1, 2, & 3. In the database, there may be over 500+ entries with one of these values assigned to it. How can I get MySQL to return just 1, 2, & 3 only once rather than several hundred times.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Mysql Doesnt Return All Results Of A Query
I have an sql query like this: SELECT column FROM table WHERE column1="3" AND column2="1" This query works perfectly if i run it in the command line, to be exactly it return two results. But if i run it from php i just get the first of the two results. Any ideas? Mysql 4.1.8 php 5.0.3 I have a second problem. But its more of a question. if i run the foreach loop on an array like this array("id" => "78"), then it splits 78 up in 7 and 8. Now you say its stupid to use a foreach for this array. But in the function there i use it the array could also be two dimensional. Is this behavior normal? I looked in the php manual but found nothing.
Query In PHP Won't Return Results In There's Only 1
$sql = 'SELECT `PageTitle` ' $sql .= 'FROM `Pages` ' $sql .= 'WHERE `PageID` = 1 LIMIT 0, 30' I have run this query in MySQL control panel and it works perfectly. When I try to do it via PHP I get no results. If I select all rows (i.e I don't specify a "WHERE") I get one fewer rows returned than there actually are.
Return Results On One Page
i have a search field on a .php page. i want to return the results on the same page i.e i dont want the action to point to test2.php but test.php which is were my search filed is sitting at the moment. how do i do this? i got this on my first page: <form method="post" action="test2.php"> Name: <input type="text" size="10" maxlength="40" name="name"> <input type="submit" value="Send"> </form> and this on the second: <?php $name = $_POST['name']; if ($name=="Friday") echo "Have a nice weekend!"; elseif ($name=="Saturday") echo "Tomorrow is Sunday!"; else echo "Please enter Friday or Saturday"; ?>
Return Search Results On Same Page
I'm struggling with this much longer than I think I need to, How do I make the results of a search display on the same page as the search, sort of beneath the 'submit' button? Thanks for helping out.
How Do I Return 10 Results Per Page Using SELECT Statement?
I'm wasn't sure whether to post this under the PHP or under the MySQL section of the forums. Since most people (I'm assuming) who write PHP script, also use MySQL, I thought I'd stick with PHP. I'm rather new to both PHP and MySQL and I'd be very grateful to anyone who can help me solve a problem I'm having at the moment. First, I'll give you an introduction to my little project... I'm developing a database in MySQL that is used to store the song titles of all the MP3s I have on my PC. I've written a basic search feature that works well. The user has 2 options: Either he can type a special "!ALL" "parameter", that I made up, to return all the songs in the database or the user may enter a few characters in the textbox and select "song title" or "artist" etc. from a dropdown to search for a specific song title or artist etc.. Hope you are following so far? Say for example the user presses submit after typing "!ALL" to return all the song titles - there could be hundreds of results. What I want to do now is display 10 results on a page, then on the next page another 10, etc. (like a real search engine!). I've tried doing it with the LIMIT statement, but like I said I'm new to this and discovered that that is not the right way of going about it. My question is this: how would I go about returning 10 matches per page? Do I use hidden form fields? What would the SELECT statement look like? What would the PHP scripting look like to setup the "back" and "forward" navigation between the result for the search?
Building Array Of Difft Results For Return
I have 2 functions that I want to call from a subroutine, and then return their results; one result is an array, the other will be an array of arrays. The first will be the information about a product, $product, with values like $product['title'], product['id'], etc. The second will be an array of arrays, each line of which contains information about an element of the product. I.e., $item[0]['title'], $item[2]['value'], etc. How would I best combine these so I can RETURN the total thing from the function, and then how would I refer to the parts in the calling code? For example, if I said Code:
Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results. I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:
Return The Key From Last Mysql Insert
How do I return the auto incremented value of the primary key from a tuple that I have just inserted into a MySql database. If that is not quite clear enough then this long winded explanation should explain what I mean: Say I have a MySql table called "n" with two columns: 1: id = Autonumber - Primary Key 2: name = Text If I insert a tuple with the following mysql command using a PHP interface: Quote: INSERT INTO `n` ( `name`) VALUES ('Paul Smith') Then a tuple with with values say (34,Paul Smith) will exist in the MySql table. 34 is the value of the auto generated primary key. The question is how can I find this value 34, which is the primary key, without running a statement like : Quote: SELECT * FROM `n` WHERE `name` = 'Paul Smith'
No Return Using PEAR And MySQL
Below is the php code (Very simple): <?php include_once('C:AppServphpPEARDB.php'); $db = DB::connect("mysql://alucard@localhost:3306/soccer"); $db->setErrorHandling(PEAR_ERROR_DIE); if (DB::isError($db)) { print $db->getMessage(); exit; } else { $result = $db->query("SELECT * FROM league;"); print 'Query returned ' . $result->numRows() . ' rows' print 'Query returned ' . $result->numCols() . ' cols' print 'Query affected ' . $db->affectedRows() . ' rows' $db->query("INSERT INTO people VALUES ('Thomas', 0);"); print 'Query returned ' . $result->numRows() . ' rows' print 'Query returned ' . $result->numCols() . ' cols' print 'Query affected ' . $db->affectedRows() . ' rows' $result->free(); } $db->disconnect(); ?> Now the problem is, when I ran this code, there is nothing return in browser.(ALL BLANK, see nothing, no error, no result, absolutely white) There was also no changes on DB.
Linking Back Into MySQL From A Return
I have a simple contact table with a catagory, name, address columns and I'm sorting it by catagory then name. My question is after I get this return how I can make each catagory listing link back into the database to return all its members in a seperate part of the page. I can make a simple echo html table loop to return the catagory data, but how do I also include an <a> link to each catagory listing so that it will then access the database and dump it into another part of the page.
Affected Row Return Values From MySQL
When I remove 10 rows from a table in a mySQL database, I am not getting 10 as the affected rows return value. I am also getting positive return values if I try to delete a non-existent entry. here is a small test script that I am working on where I am getting errors. Code :
Same Mysql Query Doesn't Always Return A Result
We have no access to a mysql NG on my provider's server, so we ask here: We have a long query (long in text) with a UNION between 2 select. We have been informed that some times the query doesn't return any result. We have tried on our server and we always get a result. BUT, trying on the hosting server, many times the query doesn't return any result and doesn't get any error. Any idea ? does Union have any problem ? how to check if the query failed ? My hoster said that sometimes the table can be locked (if the server is overloaded) and then mysql doesn't return any result, but this seems to me an aberration. the query takes about 0.0050 sec to execute when it doesn't return any result, and 0.030 when I get results
Return MySQL Table Name As PHP Variable
I've got a MySQL query something like the following: $fields = mysql_query('SELECT ItemID FROM Table1 UNION SELECT ItemID FROM Table2 ORDER BY RAND() LIMIT 1'); There's more criteria than that, but this illustrates the basics of the situation. Essentially I want to randomly select one row from either of the two tables. I've got that part down; the query is returning the results I need. However, the problem I'm having is finding out which table the query pulled the result from. I'm querying two tables and will return one result - but I need to know which table the result came from. Is there any way to assign it to a variable? If so, how can it be done?
How Do I Return Result Of Mysql Row Deletion
The data entered by a user on form 1 on page1.php is posted to delete.php to remove that row from a table. After the SQL operation the user is returned to page1.php. How can I determine the success or failure of the SQL operation so I can display an appropriate response message to the user?
MySQL Query Return Category Name Instead Of #
I Have 2 MySQL tables of interest here. Table 1: categories ID name Table 2: items ID category (this relates to the category ID in Table 1) title I want my table on my webpage to show the category name from Table 1 instead of the category number in table 2. Code:
Return Record Ranking Of A Mysql Table
I have a table consisting of names, and registration dates. I query the db "select * from users order by regdate" I want do another query for a particular user, I am looking for the script to say: user is row 15 of 30.
Trying To Return Mysql Array Items From Function
I am writing a calendar script which returns events, holidays etc.. from MySQL for days with events. This was easy BUT then I tried to return multiple events on some days and thats where I am stuck. I found some examples of returning arrays from functions from functions but they all use some form of array(Ƈ',ƈ',Ɖ') and then use a for loop... I am using mysql_fetch_array so this does not seem to work... First, here is some of the code from the function where I am returning the value: PHP Code:
Query Mysql, Return Highest Value Then Create Value +1
I have a product input form I created (with php freaks help) for my website which I input general information and specs on our products. What I'd like to do now is when that form loads, it searches a seperate table and looks for the highest "ID" number. It returns the number, adds 1 to it and displays the number somewhere on the input form for reference + error checking. When the form is submitted it takes that form and creates a record pushing that number in the correct field.
How To Convert Carriage Return In Mysql To Excel Format?
I have a varchar field in MySQL table that has carriage returns. I am trying to display this field in an Excel document. When I display this using (php_writeexcel class ) Excel I get small squares due to Excel converting the carriage returns. Is there a way to convert these carriage returns to display properly. I have already tried str_replace("","",$value) and does not work. Any regular expressions?
Mysql_free_result Return Error Saying Not Valid Mysql Result Resource
im trying to do a query which takes rows of large amounts of text data and displays them one after another. the size of the fields is causing the page to be massive in size. so to try and reduce this im trying to use mysql_free_result to clear the contents from memory. however its returning an error saying not valid mysql data when im certain that it is. is this because im using a while loop like this...? ($row = mysql_fetch_result($result)) { mysql_free_result($result); }
MySQL Results Not Working So Hot
Ok. Here I am again....probably posing a question with a solution so easy that, after looking at it for an hour, I can't figure out. Ok. here's the deal. please review the code below. Looks simple enough, right?
If/then Within MySQL Results List
I want to list job opportunities for a facility. If there are jobs in the database, I can list them without a problem. But if there are no jobs, I'd like to echo a line something like: "No jobs right now, come back later." But I can't get that line to echo. PHP Code:
Mysql Writing Results From 51 To 100
Can someone write me a mysql_query code which will get me results from 51 to 100 from $database? Don't suggest me working with indexes, because i'm also deleting some rows (for example #1 is filled #2 is not, #3 is...)
Show Next Results Of MySQL DB
How do I get it so that php reads in the first 10 results out of a MySQL database. Then when Next or something is hit it displays the next 10 results and so on.
Hyperlinked MySQL Results W/PHP
I was wondering how results to db querys have attached links to each individual result? I have a good grasp of basic PHP & MySQL, but don't understand how that works. For example, if you have a db of products, all with individual id #, how do you get one product from the query a <ahref>? Could someone explain?
Compiling MySQL Results
Does anyone know how to compare multiple results from a MySQL query? For example, I would like to query the database and collect all the results into a variable (perhaps $totalresults). Then, I would like to use a single statement to compare each of the results within $totalresults to the statement's conditions.
Getting Results From MySQL Database In PHP
I am trying to write a php page which connects to a MySQL Database which is supposed to get the results from a table within a database and display the results in a table. Below is the code that I am using:
Limit Mysql Results
I have a script which has a mysql query which returns 20 results - I want to add some validation so if my variable ($var) is empty, it only allows the user to select the first 5 results my code is: - $sql = mysql_query("SELECT * FROM greetingcards_cards WHERE category='$cat' LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ $image = $row['url']; $cardid = $row['cardid']; echo "<br><img src="$image" /><br><a href="?function=sendmessage&cardid=$cardid">Pick this card</a><br>";} I want it so that if the variable is empty, instead of displaying "Pick this card" it displays - "You must register to pick this card" and have a different hyperlink Is this type of validation possible? if so how is it done?
PHP MySQL Order Results
I'm using: $sql = "SELECT * from $myTable ORDER BY `points` DESC LIMIT 5"; in a whileloop to display the top five scorers but would like to put their position next to the results (eg, 1, 2, 3, 4 and 5) Is there an easy way to do this?
Convert MySQL Results To XML
I just got Dreamweaver CS3, and I love the built in SPRY framework. It allows you to create web applications that use a table listing, and details listing very quickly. Unfortunately the only data the SPRY framework can accept is XML. Is there a built in function to convert from a $row result from MySQL to XML? Code:
Mysql Results - Ordering Them.
i need an mysql query to rank the results, like SELECT field FROM table and to order them greatest to least by the value of a different field.
Mysql Results Pagination
I have a php code to split the results of a sql query over pages taht works great... But I need to add some feature, I need to add that if there are more than * pages it shows me "..." instead of the hole numbers of pages.. Code:
Sum All Of My MySQL Integer Results?
I have a bunch of rows, and for each row, the column "rating" has a number from 1-5. I need to add all of these together, so like if there were 3 rows with 5 for rating, it would return 15. If it's possible to do it with an SQL statement, I'll like it to average them.
Splitting MySQL Results
So I have a database, and I want to split the results into 2 columns. I don't want to alternate them, but have the first half in the left column, and the second half in the right column. How can I handle this so that it does it automatically no matter what number of entries (and so that if it's an odd number, the one overflow is on the left).
Parsing PHP Code In MySQL Results Set?
I have a PHP script that pulls content from an MySQL database and returns a result set. Is there a way I can put PHP code within a field in the database and have that code parsed as PHP code on returning a results set? If possible, I want just one field of the database parsed for PHP code. The results set is return as a straight result, not within a loop. Just inserting the <? PHP code thus ?> returns that as sources code not parsed.
Populating Array With Mysql Results
I'm returning a result set of one field in a table, and want to populate an array with the results. I can't for the life of me figure out a simple way to do this without using mysql_fetch_array() to cycle through the results, append that to a var, then explode that into a var and pass that. PHP Code:
MySql - Outputting Results In Groups
I want to output mysql data by groups (states). However each time php/mysql comes to a new state in the results I want it to print the state name before putting the results. Does php have some sort of memory function to recognize when the state has changed?
Mysql Results Output Problem
I trying to set up some subdomains and I'm at the early stages of just testing the the thing . I have set up a small test DB, with the following fields, company, id, url. I have also set up a test page to see if the output corresponds with the subdomain name. If the domain exists the result with echo "domain exists" if not it will output "does not exist". But the page just says "does not exist" all the time even though the domains are set up.here's the code:
Exploding Results Of Mysql Query
I have a table with times and dates listed like this: 0000-00-00 00:00:00 2003-09-20 20:26:22 etc etc What I want is to query the DB for the field (matchdate) and then get it to explode the ' ' to give jsut the date for me and then put it into a dropdown in a loop. this may sound easy but i too sleepy to work it out and searching aint good.
Store Mysql Results Into An Array
i just started using php. i've used it before as a maintainer. fun stuff. well now i'm the writer. i want to abstract all the DB commands away from myself and all other developers. so i'm writing a function to query the php database from all users of the database and store them into an array as a return value so that i can seperate my database code from my html creation code. 1. is there a way to put all my database functions into a php file and include that file into all my other php pages? similiarly to a #include in C++ or a import package name in Java? 2. my code to run down the fetched results and store them into an array doesn't seem to be working the way i want it to. if i print out the results from the mysql returned fetch the data is fine. however the array seems to print out "Array[elementnumber]" instead of the value. Code:
Mysql Results <-- Previous Row, And Next Row, Showing Next Ok
I query a database and return a result on the column "reference". There might be 7 listings. Each row is displayed in a table, with links through to a detail page. I am working on having a "previous" record and a "next" record link on the detail page. This code below works, for the "next" record, by searching the values in the array $myarray for the variable $ref. It then returns the key value and the key value, as a number, is deducted by one and plus'd by one to give me the previous row and the next row. Returning the value of the next row works a treat, but for some reason the previous row, deduct 1, while it echoes a value to screen, doesn't work. This is the code: (query database and then:) //$ref is a variable carried into the page $num_rows = mysql_num_rows($result2); $i=0; while ($i < $num_rows) { $next=mysql_result($result2,$i,"reference"); ++$i; $myarray = array("$i"=>"$next"); foreach($myarray as $key=>$value) { if ($value == "$ref"){ $b=($key); $c=($key+1); $a=($key-1); }} if ($a == "0") { echo "No Preceding Record"; } else { if ($key == "$a") echo "<a href=../detail/index.php?name=$value>Previous Record</a>"; } if ($key == "$b") echo "This is the current Record"; if ($num_rows < $c) { echo "Records End"; } else { if ($key == "$c") echo "<a href=../detail/index.php?name=$value>Next Record</a>"; } } } else {
JOIN Table Results W/MySQL
I have a query with a simple JOIN. For example: SELECT * FROM Companies INNER JOIN CompanyTypes ON Companies.CompanyID = CompanyTypes.CompanyID The query returns all fields from both Companies AND CompanyTypes. I would like all fields from Companies only.
Counting Results From A Mysql Database
I want to know how many results throw a query in order to know if they have reached a limit.I.E. $sql = mysql_query ("select * from classifieds where user='$username'"); while ($row = mysql_fetch_array($sql)){} I want to check lets say that only 10 classifieds per 'username' can be created. If ten or more classifieds are in the database for that 'username' then show error message.
Alternating Row Colors With MySQL Results
Is there any way i could make a image for the alternating row colors instead of a strait bold color, for instance: $color1 = "#CCFFCC"; $color2 = "#BFD8BC"; Would there be anyway to link an image in there? I have tried it this way: $color1 = "<img src='..style1.jpg'>"; $color2 = "<img src='..style2.jpg'>";
MySQL Query Not Returning All Results
I have a user table in the DB, for example: +---------+----------------+-------------------+ | uid | username | firstname | |----------+----------------+------------------+ | 1 | cobby | Andrew | | 2 | admini | test-account | +---------+-----------------+------------------+ If, in phpMyAdmin, I query: SELECT `username` FROM `users`; It will return results correctly (cobby and admini, respectively). But if I make a simple PHP script, such as: <?php mysql_connect('localhost', 'cobby', 'dbpass'); mysql_select_db('testdb'); $query = mysql_query('SELECT `username` FROM `users`'); print_r(mysql_fetch_assoc($query)); ?> It only returns: Array ( [username] => admini ) Why does it only return the second result? I have a feeling I'm doing something really silly, but I looked over this test script and its got me stumped.
|