Select Statement - Select Random ID #
I have made up a page that pull info on 13 branches of stores onto one main page. It's basically there to display all the branches on one page... then you click on the one you're interested in and then you go to a more detailed page.
Back to the main page. On the top, there's kind of a featured branch that has a bigger picture and bigger title but it's still getting pul pulled from the same table etc etc etc.
In order for me to avoid favortism to one branch (and for other branches to start complaining) I want to ramdomized the order every time someone came to page but I have no idea how.
right now I have a super simple select statement.
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiple Select From Listbox And Execute A Sql Query Select Statement
Supposing i have a html form with 2 listbox and i name it status and resolution. So it goes <select name='status[]'>... <select name='resolution[]'> Then i have a another php page. $status = $_POST['status']; $resolution = $_POST['resolution']; Now my question is, how do i do the sql query statement? mysql_query("SELECT * from bugs where status=$status and resolution=$resolution"); The problem is, i select 3 options form the status listbox eg. new, closed, duplicate. And from the resolution, i chose fixed, invalid.
Random Select
Is there a way to either select a random row from a column in an MS SQL table or from an array? If so how would I go about it?
Random SELECT
I'm building a small random quote script, and I'm having some troubles starting from the fetch_array. while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { So starting from here, I need to determine how many results my query returned. I don't know how to do this.(for example, save it to $i) Than, it needs to randomly generate a number between 0 and $i. I don't know, how to do that . Than, it needs to select just that result from the query and display it.
Random Select Issue
i have used the following piece of php code to select a random image from a mysql database to display on my site, adding to its completely dynamic nature. i have had problems with my server people though who refuse to install mysql and instead use access. i was wondering then if there is a way to make a random selection like this but just from a specified folderand without a database backend.
Random Element(s) Select?
I'm trying to create a page that displays an image, but also has a specific text string and link associated with that image. There are 5 images, and I want a way to select randomly one of these images with its appropriate info. I've seen a lot of scripts already that select an image from a text file, or a database, or a directory of images, but I want to do it with arrays. I suppose I would have to use associative arrays. PHP Code:
Select Random Array Value
I have an array which has $key and $values set. I want to randomly select one of these values. How would I do this?
Select Statement Problem
I am having a problem with simple select statement When I run this statement in my PHP program.. no result.. $sql= "select * from zipcodes where zip between $pluszip and $minuszip"; But when I run the below statement I get the results.. $sql= "select * from zipcodes where zip between 12345 and 12456"; I tried this one also, but no result $sql= "select * from zipcodes where zip between '$pluszip' and '$minuszip'"; I tried echoing pluszip and minuszip and i am getting the values printed. I am having trouble with passing it on to the select statement.
Versatile SELECT Statement
My SELECT statement below works if I have made an actual selection for the area_ID, but when I generate the page initialy no selection has been made yet which results in zero hits for the current version_ID. Do I need to make an additional SELECT statement and remove PHP Code:
Error In Select Statement
I have the following SELECT statement which aims to select data from the database for a month ago today however im getting an error message as shown below. SELECT STATEMENT $dbQuery="SELECT * FROM data WHERE ReportedDate BETWEEN date("Y-m-d", strtotime("-12months")) AND date("Y-m-d", strtotime("-11 months"))"; ERROR MESSAGE: Parse error: parse error, unexpected T_STRING
Password() And Select Statement
problem in retrieving a row form a table that I created in mysql db. I insert these values in the table 'Bell',password(ì«'). But the problem is in my php application I cant retrieve this row because the password that I pass dosn't match the password value in the table. this is the code that I wrote in my php application $user = $_POST[username]; $pass = $_POST[password]; $q = mysql_query("SELECT * FROM admin WHERE username = '$user' and password =PASSWORD('$pass')"); if(mysql_num_rows($q)==0){ echo "Acces denied. User not allowed to connect."; mysql_close(); } else { echo "<script>window.location.replace('administrator2.php')</script>"; }
Select Distinct Statement
I have a question about the following PHP script - I got it off a web site tutorial on how to count users logged into your site - my question is the $PHP_SELF variable - it writes the name of the web page to the 'file' field in the table - I don't understand why it is doing that - I mean, isn't the SELECT DISTINCT statement only pulling those records from that one web page? I guess I just don't follow what it is doing with that SELECT DISTINCT statement? $timeoutseconds = 300; $timestamp = time(); $timeout = $timestamp-$timeoutseconds; $php_SQL = "INSERT INTO online SET timestamp='$timestamp', ip='$REMOTE_ADDR', file='$PHP_SELF'"; $php_resultID = mysql_query($php_SQL, $php_linkID); $php_SQL = "DELETE FROM online WHERE timestamp < $timeout"; $php_resultID = mysql_query($php_SQL, $php_linkID); $php_SQL = "SELECT DISTINCT ip FROM online WHERE file = '$PHP_SELF'"; $php_resultID = mysql_query($php_SQL, $php_linkID); $php_users_online = mysql_num_rows($php_resultID); if ($php_users_online == 1) { print "<BR>$php_users_online user is currently online"; } else { print "<BR>$php_users_online users are currently online"; }
Select Statement Not Valid?
I'm doing a search via the passing of values throught the url. I'm having a problem with the select statement. If i enter the values and the match (side1='$valueSide1' AND side2='$valueSide2') portion of the statement the correct values are returned. But if I reverse the values and the do match (side1='$valueSide2' AND side2='valueSide1') then no match is returned. I've verified through command line that the statement works. Does it look like my statement if formatted correctly? Code:
Variable Select Statement
I would like to have a form that gives the user choices for selection parameters for email, printing etc. A real simple example: Give me all ______ who ______ when _______ where _______ I can figure this out if all of the selections are filled, but NOT if they just decide to use only one of the selection choices. I'm sure this is idiotic, but I'm really new to php and my ideas are writing checks my programming skills can't cash.
Simple SELECT Statement
I have a dbase with some gigs that has a date field. The SELECT statement currently says... QuoteSELECT * FROM `Gigs` ORDER BY `Eventdate` ASC LIMIT 3 which works fine but I also want the statement to only show gigs that havent happened yet or that are > than today's day. I tried WHERE Evevntdate > CURRENT_DATE or something along those lines but so far havent got it to work.
Strpos In A Select Statement
I am trying to query a Access database using the following code but I get an SQL error Syntax error (missing operator) in query expression. Is it possible to use strpos in a SQL statement? pro_id is a field in the database whose value is 489 $valves = 489; $SQLQuery = "SELECT * FROM Products WHERE strpos(".$valves.",pro_id,1) !== 0";
Maximum Lenght Of Select Statement
Can anyone tell me what the maximium length of a SELECT statement can be. I am coming from Foxpro where 8100 char was the limit. Part of my program is a query builder and I need to build a query from a series of drop down lists users select values from.
Question Regarding A MySQL SELECT Statement
I tried hunting for a MySQL specific NG and didn't find one but I did see that MySQL questions get asked here. If this isn't appropriate and you know of an appropriate NG then that would be great. In one table I have inventory... table name is "inventory" columns are.. ----------------------------- item_number item_name ----------------------------- 1 radishes 2 carrots 3 potatoes 4 oranges etc..etc Table two is "sold" ------------------------------ date item_number 13Mar 1 14Mar 4 15Mar 2 16Mar 1 What I am querying is the table "sold" for the Unique items (1,4,2) and then retrieving their names from table 1. My query below isn't working.. SELECT item_name FROM inventory WHERE inventory.item_number = sold.item_number; I am just now starting to get into complicated MySQL queries and actually the more I learn about it the more I love it.
PHP, ODBC, SQL Server Select Statement
I am having a problem getting results back from a SELECT statement using the script below. The field names contain decimals and I am not sure wether or not this is causing the problem or not?? I am connecting to a SQL server db using ODBC, first time connecting to SQL server but have been using ODBC to connect to Access db's for years. I have entered the field names just as they are in the table and I have tried replacing the spaces and decimals with underscores but still recieve the same error. Anyway, my simple script and the error that I am recieveing is below. Any help would be greatly appreciated.. $connect = odbc_connect('cabngsql', '', ''); if (!$connect) { echo "couldn't connect"; exit; } $query1 = "SELECT fol no FROM Protocol.folder"; $result1 = odbc_exec($connect, $query1); while (odbc_fetch_row($result1)){ $folder = odbc_result($result1, 1); echo "$folder"; } ?> ERROR: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Protocol.folder'., SQL state S0002 in SQLExecDirect
SELECT Statement Syntax For Variables
the statement below isn't returning the expected results. I've echoed it at runtime and the variables are missing. I presume it's just the syntax? $query = "SELECT field FROM database.table WHERE email='$e' AND password='$p'";
Paginating Random Select Query Results
I am just starting with PHP/MySQL and using Dreamweaver MX 2004. I am selecting a subset of records from a table, then ordering them using RAND() and then displaying 6 at a time on a page. So far so good but there is one major problem, namely, when you move from page to page viewing the results the query is rerun for each page which means that you end up duplicating results. What I want to be able to do is run the query once and then page through the returned results without duplication. Also to be able to go back & forth between pages and see the same set of results. Here's a simplified example: Suppose I have 12 records (call them A - L). The query : SELECT * FROM Table WHERE Criteria = 1 ORDER BY RAND() Which returns: D F K A L F J H G C B I So my pages should show the following: Page 1: D F K A L F Page 2: J H G C B I And I should be able to switch back and forth between these pages and always see exactly the same records each time. However what I see at the moment is: Page 1: D F K A L F Page 2: F B C A E D (Note duplicates from Page 1 because query has been re-run) Page 1: C B F A K L (Note duplicates again plus results not the same as previous visit to Page 1)
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?
Getting Form Info Into A Mysql Select Statement
I'd like to get user input from an html form into a mysql select statement. Here's where I'm stumped: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%search-string%'",$db); I need to get the user's input into the '%search-string%' section, but I do not understand how to do this. I can hard-code a specific search string and it will work, but I want the users to be able to dynamically define the search-string. So, I created a basic html form and used the post method to grab their input, but now I can't insert that input into the mysql select statement. Any ideas? I think it should be easy, I just don't know how to do it. I've tried this: $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%$_POST["search"]%'",$db); But it doesn't work. Below is the form in html and the php file: <html> <title>Search Test</title> <head> </head> <body> <form action="search-db.php" method="POST"> <p>Enter Your Search: <input type=text name=search></p> <input type="submit"> </form> </body> </html> ----------------------------------------------------------- <html> <body> <?php $db = mysql_connect("localhost", "Anonymous"); mysql_select_db("computers",$db); $result = mysql_query("SELECT * FROM dept WHERE notes LIKE '%surplus%'",$db); echo "<table border=1> "; while ($myrow = mysql_fetch_array($result)) { printf("<tr><td><b>%s</b></td></tr> ", $myrow[notes]); } echo "</table> "; ?> </body> </html>
Mix Two Tables In A Single SELECT Statement - Not A Join
I have an Intranet with the organisation I work with. In this organisation there are two departments - community department and press office. Both the community department and press office have thier own news system where they can add news in their own admin section that will appear on their homepages. Both admin section have their own DB table thus two seperate tables. I would like to select all the rows from both tables in a single SELECT statement so when I output them they will be integrated. This is not the same as a table join as their are no keys and I want the rows from both to remain seperate. Can this be done? Could someone please post an example SQL statement demonstrating this if so?
Run A Select Statement Based On Array Values?
I have an array that has x number of values. I want to run a sql statement x number of times using the next array value each time. Basically I have a query that displays results based on a search. The result of the search is a list of names, the trouble is for reasons beyond my control the names are in a single db field as "FirstLast". I want to take this value and match it up to another table that has the first and last names in separate fields. So far I have extracted the results from the first query using a while loop, the resulting array is called $name_search: Code:
SELECT Statement Results Into Text File
I am trying to create a text file based off the results of a query statement from a database. See code below: $itemq = "SELECT sdlitm, sddsc1, sduorg, sdlnid, sduncs FROM F4211 WHERE sddoco = $ordernum AND sddcto LIKE '$ordertype' ORDER BY sdlnid"; $result3 = odbc_exec($connect, $itemq); while (odbc_fetch_row($result3)){ $partnum = odbc_result($result3, 1); $desc1 = odbc_result($result3, 2); $qty = odbc_result($result3, 3)/100; $position = odbc_result($result3, 4); $uncs = odbc_result($result3, 5); $extcost = $uncs*$qty; $total = ($total + ($uncs * $qty)); $filename = "$reportnumber.txt"; $fp = fopen($filename, "w"); fwrite($fp, "Activity Number: $reportnumber "); fwrite($fp, "Warranty Type: $reason "); fwrite($fp, "Customer Name: $custname "); fwrite($fp, "$qty $partnum $desc1 "); fclose($fp); Everything works fine until I get to the line: fwrite($fp, "$qty $partnum $desc1 "); This line should actually print multiple lines into the text file as these are the line items from an order. There could be anywhere from 1 to 20 lines written to the text file. As it stands, the only line items written to the text file are those of the last line found on the order. The entrie script dealing with the text file are still within the confines of the while statement curly braces. How do I write these lines out in the text file??
MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query. However, I am not able to extract the result of any of the UNIONED selects. $query1 = mysql_query (" ( SELECT SUM(deposits) AS total_deposits FROM table1 ) UNION ALL ( SELECT SUM(withdrawals) AS total_withdrawals FROM table1 ) ") or die (mysql_error()); $result1 = mysql_fetch_array($query1); extract($result1); When I echo the results of the second select statement I get nothing. echo $total_withdrawals;
Select Statement With Changing Tables Base On User Selection
I am trying to make a select statement that would allow me to change the table, base on the user selection from a drop down menu list. I don't know if its possible or my syntax is wrong PHP: sql = SELECT * FROM "'.$_POST[Tableselection].'" WHERE "'.$_POST[userid].'" ='1';
SELECT *
If I have a lot of articles, all with a unique IDs. First I would like to search for that ID, I could do SELECT * from ARTICLE where ID = xx But I also want to display the 5 articles before and after that article. SELECT * from ARTICLE where ID > xx LIMIT 0, 10 and SELECT * from ARTICLE where ID < xx LIMIT 0, 10 (I choose a limit of 10 in case the ID is one of the first one or one of the last one, that way I will always have at least 10 articles). Is it possible to do the above in one single query? Should I even bother doing that? does it make the whole operation faster to do it that way?
Select Box
I have a problem that I'm not quite sure what algorithm will help me on. I'm bringing in records from MySQL using PHP and need to spit this records into a select box. Fairly simple, here's my code for the first select box: <option selected value="<?=$currentCatID?>"><?=$currentCategoryName?><option> <?php while($rowGetCat = mysql_fetch_array($resultGetCat)){ if($rowGetCat['pCatID'] != $currentCatID){ echo "<option value="".$rowGetCat['pCatID']."">".$rowGetCat['pCatName']."</option>"; } } ?> </select> Problem is - based on their choice with the first select box, I need to query the DB and populate a second select box. So basically, I need a 2nd select box that is populated on the fly based on their choice from the first select box. The only solutions I have found so far use their own form, and the form I have now has numerous other options and values that I need to save the state of for editing. I was thinking AJAX might help, or maybe just regular javascript, but without having the entire page reload I'm not sure.
Sub Select
I have this line of code: $result = mysql_query("SELECT jobnumber, projectname, description FROM timesheets WHERE description IN(SELECT distinct jobnumber, projectname FROM timesheets)",$db); But this returns nothing. What I want it to do is display the 3 fields jobnumber, projectname and description where the jobnumber,projectname combination is unique.
Select The Id And The Name
I have this code that when the user provide his email address he will participate in a raffle, my problem is that i want to select the id and the name but my selection is not workin Code:
Select From
Is there a way to select from multiple mysql tabels?
Value To Use To Select All
I have done the following query: $query = sprintf ("SELECT * FROM users WHERE country LIKE '$selCountry'"); $result = mysql_query($query,$link); I want to obtain the users that are from a certain country but when $selCountry is equal to "All" I want to obtain all of them. I have tried the query in mysql webpage using '%' and it works but when using this character from the php file it doesn't work.
SELECT *
What would I have to put within the $sort variable to have that request display all rows starting with a number? right now I have to put 1,2,3,4,5,6,7,8,9 seperate. Anyway I can include it all in one variable that would work below? $q = 'SELECT * ' . ' FROM `company_details` ' . ' WHERE `cname` LIKE '' . $sort . '%'' . ' ORDER BY `cname` ASC'; $r = mysql_query($q);
SELECT MAX()
$f1 = mysql_query("SELECT MAX(id) FROM topics WHERE fid = '$f'"); $f2 = $f1+1; now, I can't see any errors...but when I ran my code $f2 should have equalled 4, but somehow it came out with 12? what's wrong with it??
Select Box
I have a select box coded that displays MySQL data as options in the pull down menu. What I need to know is if and how I can make it so that each option has given background. Can I assign a class to each option? The code for my select box looks like this: Code:
<select>
I have a query regarding <select> name: The script runs through a for loop for each select which gets the qty's from the DB, so the user can only select the maximum thats available in stock. Each select is given a name, which is the record ID from the DB ($wsi_id_arr[$num]). So the first select will be <select name="VB001"> for example. However, the problem i am having is how do I get at this in another script, for example, so far I have: for($ordercnt=0;$ordercnt<$num;$ordercnt++) { if(...................
Cannot Pass @ For A SELECT... WHERE
From a cycling database, to put to screen the Clubs whose Secretary has email, this works just fine in phpMyAdmin - select email from clubs where email like "%@%" order by club I want to do it in php but from the manual and these DevShed files, it seems the @ character stops all further progress along the line it's on???? I've tried all kinds'v variations of the following, brackets on and off, double and single quotes, till I'm blue in the face.
Help With Select Count In PHP
I'm trying to do a script that tells me how many orders I got in on a particular day. The script loads, but nothing shows up. Any help would be greatly appreciated! Here it is: <? //create connection $connection = mysql_connect (localhost, xxxxxx, xxxx) or die ("Couldn't connect to server."); // select database // substitute your own database name $db = mysql_select_db (MyDB, $connection) or die ("Couldn't select database."); $date = "02/05/02"; // create SQL statement $sql = "SELECT COUNT(*) FROM CUSTOMER as mycount WHERE CREATED='$date' AND STATUS=Ɔ'"; // execute SQL query and get result $sql_result = mysql_query($sql,$connection) or die ("Couldn't execute query."); //start results formatting echo "<br><br><div align=center>"; echo "<table cellpadding=5 cellspacing=0 width=ྛ%'>"; echo "<tr bgcolor='#336699'> <td width=100% valign=top><font face='verdana,arial,helvetica' size='-2' color='#ffffff'><b>Orders Today:</b></font></td> </tr>"; // format results by row while ($row = mysql_fetch_array($sql_result)) { $mycount = $row["mycount"]; echo "<tr> <td width=100% valign=top><font face='verdana,arial,helvetica' size='-2' color='#000000'>$mycount</font></td> </tr>"; } echo "</table>"; echo "</div>"; /free resources and close connection mysql_free_result($sql_result); mysql_close($connection); ?>
Select The First Letter
I'm trying to do a query, but i want the query to be done using only the first letter of the values in lname. ("SELECT * from wisdom where lname == '$letter' "); "Letter" is the value that i want generated coming from the previous page. I want all the data from lname with A as the first letter selected so i can display them.
MySQL Select
Just a qucik question. I need to display everything from the table where the data is not null, apart from username, as they'll always have a username. So far I just have this, which is on the assumption they have entered their name. $get = "SELECT * from profiles WHERE name IS NOT NULL LIMIT 30"; Is there a way I can basically make it say. Select * from profiles where * but username is NOT NULL?
Select Value In A Table
In my sql table I've a list of colors: white, blue, green..... table colors: idcolor, coloname 1, white 2, blue 3, green..... I've some programs sending colors for some material, but I don't want to use them, I'd like to use my values: example: program gives 'dark blue' then I'd like to select blue in my table and...
|