Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    PHP


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





Conditional Select From Mysql


I have a mysql database which stores race data that I want to open up to users for viewing. I want the user to be able to select various subsets of the data according to the parameters: race, gender, age, and type (and maybe sometime, by name as well). This is BOTH a mysql question and a php one, as I ask for a more efficient solution (see bottom this post).

Here is a snippet of how I am implementing the mysql statements to select only the exact subset of data. PHP Code:




View Complete Forum Thread with Replies

Related Forum Messages:
MySQL Conditional Statement
What I am trying to do is kind of like an advanced search. Basically, I have three dropdowns, for this I am going to use the example books: Three dropdowns, which are

1) Author
2) Language
3) Type (Hardback or Paperback)

Typical search: I want to get a list of all books written by STEPHEN KING, that are written in ENGLISH and that are HARDBACK ok fine, but what if I just want to search for ALL books by STEPHEN KING regardless of the language or the type of book?? Heres the SQL i would use for all 3 "search parameters": PHP Code:

View Replies !
Mysql Real Escape String() In Conditional Statements
I created the following bit of code that allows me to pass a MySQL conditional statement to a function.

I am trying to figure out where and how would I go about incorporating the mysql_real_escape_string() function?

Is there a way to call the mysql_real_escape_string() in the function itself? Code:

View Replies !
MySQL+PHP Select One Row
I'm sure it has been asked a thousand times before, but still:

How can I access a particular row in my MySQL table via PHP?
The background is just to update the values of one row in the table via
a html form with the old values already filled in.
What I tried so far ist sth like this:

$row=mysql_query('SELECT * FROM names WHERE ID=$entry');
for ($i = 0; $i < mysql_num_fields($row); $i++)
{
echo("<td>$row[$i]</td>
");
}

The mistake should be that mysql_query does not return a vector, but
still a table...

Does anybody have a good idea how to solve that problem?

View Replies !
MYSQL SELECT?
In my code I am trying to SELECT username and UsrRights When I Echo out the SQL query I do not get anything back. Why am I not getting anything echoed back? Code:

View Replies !
Mysql Select Via Php
Everything works. I just want to make a table of results show up in alphabetical order.

I have mysql select whole table. I want to take the mysql select and select the whole table with one field alphabetically. A to Z. How do I do this?

View Replies !
Mysql Select From Db
I'm writing a guestbook and I got stuck on the part of the script that selects the posts from the database (mysql) and prints it to the page. The code is below:

$result = mysql_query("SELECT * FROM table_name WHERE active =&#391;'");
$row = mysql_fetch_array($result);
print "$row";

This is a very basic script, I'll add the bells and whistles later but first I need to get this part to work. When I go to this page with my browser, I get the meta title tag but nothing in the body of the browser.

View Replies !
Mysql Select
I'm creating ad's system. There are two mysql tables: `ads` and `views`. In `views` i put the ids of `ads` table's entries. How to select from `ads` only rows, which ids don't exist in `views` table?

View Replies !
Won't Select From MySQL DB
I am trying to make it so my script will show a drop down form of all accepted credit cards from a certain table called devbg_credit_cards. I've checked all the spellings / letter cases and it's all right....but for some reason it won't show those credit cards in my options... any ideas? Code:

View Replies !
Select From A Mysql Table
I want to pull one field from a mysql table. How do I do that? Do I use SELECT? The field name is $sip_visitornum. And I want the last value that was inputted in to the db. I already have the code to get the visitor number but I don't know how to display data from the database properly. Thanks.

View Replies !
MYSQL - Select XX Months
I have a database set up, with one of the fields is a month -

"200611" = November 2006
"200610" = October 2006
"200609" = September 2006

I was wondering, I know how to sort descending etc.. - Is there a way,
to (add to an existing search criteria).. select all records in the
last XX months..

IE, If I only wanted the last 2 months, it will only select records in
October & November 2006....

or September also - if I want 3 months...

(I have records going back to April 2006)

Im guessing the 'unique' function will be used, but im not sure how to
select XX months.....

View Replies !
Negative SELECT In Mysql?
How does one retrieve the rows in a select statement that DONT match the
select.

select CarIndex FROM DealerCatalog, BigCatalog WHERE
DealerCatalog.CarIndex=BigCatalog.CarIndex

finds all the cars in the dealer catalog that are in the bigger distributor
catalog.

How do I do the opposite in a single sql statement i.e. all the dealer cars
that AREN'T in the big distributor catalog?

View Replies !
Mysql Query - Select Any
I have the following sql statemant to search a mysql database that gets
if values from a form with combo box's in.

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' AND hottubs.shape = '%s' ORDER BY
$thesearchtype_search.

Everything works fine except I want to add a select "any" from the
shape combo box. I really need a way of cutting out the last " AND
hottubs.shape = '%s' " if the $_GET['shape'] = 'any'
Will this work using a variable as shown below??

IF ($_GET['shape'] != 'any' )
{
$shape = AND hottubs.shape = '%s'
}

SELECT * FROM hottubs, manufacturers WHERE manufacturers.manid =
hottubs.manid AND hottubs.type = '%s' AND hottubs.dimlength <= '%s' AND
hottubs.dimwidth <= '%s' AND hottubs.dimhight <= '%s' AND
hottubs.seatsto <= '%s' $shape ORDER BY $thesearchtype_search

I have only been doing php about a month so go gentle!

View Replies !
MySQL SELECT Returns.
How would one go about retrieving data from a MySQL table, and then breaking it up into groups of, for example, 5.

What I am trying to do is pull search results from sed table, and then be able to have links at the bottom that would be like "<Previous 1, 2, 3, 4, 5, 6, Next>" where the numbers represent the dynamic amount of pages listing the search results.

View Replies !
(mysql) Select And Indices
Trying to write a php script where the user will enter the row number
(index) of a record. Say, for example, user wants record 55:

[MySQL]: select * from MyTable where Index = "55"

where Index is an autoincrement value, and also an index.

Unfortunately, MySQL barfs on this type of instruction. Doesn't seem
to want to let me access Index values...

View Replies !
Select Multiple & Mysql
What's the sql should look like to get all possible data when using multiple select,
such as: <select name="hostfield[]" multiple> PHP Code:

View Replies !
Run A Sql (select) Statement On A MySQL DB
I am trying to run a sql (select) statement on a MySQL DB, using the sum function...
It keeps returning a value that I know is not correct (in fact it is 1.3356959598149e-315)...

The statment is: Select sum(domain_cost), sum(domain_charge) from table_name;

I know the answer should be about $12,000, but it is clearly not giving me this... Is there a formatting that needs to be included in the statement.

View Replies !
MySQL Select Case
I'm trying to get the venue in the 'List' column when in contains a
value. But if the venue Is Null then place the event in the 'List'

SELECT
CASE
WHEN event Is Null THEN venue
Else
event
End as 'List'
,DATE_FORMAT(fld_date, '%M') as Monthly[color=blue]
>From na_statistics[/color]

View Replies !
MySQL: Select Row Numbers
I would like to be able to do something like this...

select name,dob from employees where [rownum] > 10 and [rownum] < 20;

.... results from this would show me data from the 10th, 11th,... and 19th
row.

View Replies !
MySQL Select From (no Column)
Is it possible to select from a table using WHERE without putting in a column name? Kind of like this: mysql_query("select * from flights WHERE  LIKE '{$searchfield}'");

View Replies !
MYSQL Select Code.
Im trying to make this somewhat statement which says through mysql_query(); somthing like:

("SELECT username = $user FROM user_info WHERE rights = $rights");
// then put $rights which has been never been valued before
$_SESSION['RIGHTS'] = $rights;

So correct me if im wrong i want to do something like this. if anyone could help me form this up in a formal mysql_query manner, since ive done a lil search but didnt find much about it.

View Replies !
Mysql Select Problem
Currently im using this:

$query = "select * from news, users where news.User_ID = users.User_ID order
by news.News_ID DESC"

only problem is both tables have User_ID, how can I make aliases of these?

View Replies !
Mysql Select Query With Php
I want to create a sql query but don't know if this is possible with mysql. The Query should do the following: Select all db entries from table in which entry a is smaller than the number (count) of all db entries with criteria x from another table.

View Replies !
Mysql Select Date From
if I have something like..

$result = mysql_query("SELECT * FROM booked WHERE Date=&#55614;&#57159;-04-07'")

which just list items for that one day, how would I list everything from a date to a date in the future. ie like 2007-04-07 to 2008-04-07 .

View Replies !
Mysql Select Displays Nothing
I'm having some trouble with this script. I have within a table the column "item1name". When I try and run this script everything echos out okay yet the final if statement always displays nothing when there is actually text in the column specified. Any ideas why this is happening?

<?
$userid="2";
$refslot= "item1";
$ex= "name";
$refiname= $refslot.$ex;
echo $refiname;
mysql_connect("localhost", "xxx", "xxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());

$query= mysql_query("SELECT * FROM pcitems WHERE userid='$userid'")or die(mysql_error());
while($row= mysql_fetch_assoc($query)){
$iname= $row['$refiname'];
echo "Working";
................

View Replies !
MySQL Select Statement
$query = "SELECT DISTINCT albumName FROM fotoPhotos, fotoUsers WHERE fotoPhotos.userid = fotoUsers.id AND fotoUsers.username = ".$username." ORDER BY albumName ASC";

I don't get an error message. The variable $username is set and exists in the database.

But there is something wrong that I cannot fathom.

View Replies !
MySQL Select From Array
I have two DBs, one is of dealerships and one is a zip code DB.

I'm using ZipCodesRange.class from phpclasses.org

Example:
include("ZipCodesRange.class.php");

//initialization, pass in DB connection, from zip code, distance in miles.
$zip = new ZipCodesRange($db,&#65533;',50);

//do the work
$zip->setZipCodesInRange(); //call to initialize zip array

//zip code output, other processing can be done from this array.
$zipArray = $zip->getZipCodesInRange();

It returns an array of zip codes and distances ($zipArray, $zipArray[0] = Zip, $zipArray[1] = Distance).

What I'm trying to do is SELECT dealerships from the DB of dealership within the returned zip codes. But how do I SELECT from an array?

Ideally, I would want to select dealerships from a given radius of a zip code and show the distance without using lat/lon.

View Replies !
Multiple Select Into Mysql
I want to insert multiple selection into mysql like this:

<select name="time" multiple="multiple">
<option></option>
</select>
i tried this
$arr = $_POST['position'];
foreach($arr as $position){
$time=$position;
}
.
$insert = mysql_query("insert into $table values ('NULL', '".$_POST['time']."'

but it's not work it insert into mysql just one value i want when the user ctl+click to choose more than one to insert all selected values into mysql.

View Replies !
Php MySQL Select Fails
I have a mysql problem that has me completely stuck:

If I run the following query in phpMyAdmin, I get 4 results:
SELECT * FROM b4ads WHERE instr(lower(comments),'erika')>0

But, if I insert the query into a .php file as the following line, I only get 3 results:
mysql_query("SELECT * FROM b4ads WHERE instr(lower(comments),'erika')>0",$dbq);

Even if I use the working phpMyAdmin results via the "create PHP" link, it does not work when I insert it into the php file (I still only get the 3 results):
$sql = 'SELECT * '
$sql .= 'FROM `b4ads` '
$sql .= 'WHERE instr( lower( comments ) , 'erika' ) > 0 LIMIT 0, 30'
mysql_query($sql,$dbq);

IMPORTANT HINT:

If I Edit the excluded result in phpMyAdmin, and "Insert as a new row", the new (exact same) row DOES show in the php query.

View Replies !
MySQL Data Into A <select>
How to get the mysql data into a <select></select> field. I am fimilar with ASP and know how to do it. In ASP the process is:

While Not Rs.EOF
<option value='Rs(0)'>Rs(1)</option>
Wend
Rs.Movenext
Rs.Close

View Replies !
Single Mysql Select
I have a simple array named j12stuff that is a list of words. Can I use one mysql query to select all words from a table that matches the words in the array that are nouns? The point is to use mysql to reduce the array list to nouns only.

View Replies !
Mysql Select Syntax
im trying to do a basic search query but i cant quite get the syntax down for what I want to do. I have something like this, im not quite sure what im missing. PHP Code:

$search =$_POST['txtSearch'];
echo "This is the search query: ". $search;

$sql = "SELECT * FROM articles WHERE message LIKE '%search%' ORDER BY id DESC LIMIT $from, $max_results";

View Replies !
Multiple Select And Mysql
<select name="time" size="4" multiple="multiple">
<option selected="selected">None Selected</option>
<option>Full Time</option>
        <option>Part Time</option>
        <option>Contract</option>
        <option>Temporary</option>

you know this select but who know how to enter all of selected values to database
couse when i tried to submit the form it's insert just one value from all values selected
so how can i fix it.

View Replies !
MySQL Varible Select
Is this correct:

mysql_fetch_array('SELECT * FROM `applications` WHERE `id` = ' . $id)

I get an error:

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

View Replies !
Mysql Select Query
PHP Code:

<?php
include 'common.php'
include 'db.php'

if(!isset($_POST['register']))
{
header("Location=register.php");
}
else
{
dbconnect('rishaorg_members');
}

if($_POST['newid']=='' or $_POST['firstname']=='' or $_POST['lastname']=='' or $_POST['address']=='' or $_POST['city']=='' or $_POST['state']=='' or $_POST['country']=='' or $_POST['birthcity']=='' or $_POST['birthstate']=='')........

View Replies !
MySql Query With SELECT
The following query used to work on older PHP. I have upgraded to PHP 4.3.2 and now it stopped working. No problems connecting to db can even print the variables used for search. But it seems as if the variables aren't presented to the query:

$result = mysql_query("SELECT username, name, surname, email FROM forums_auth WHERE username ='$_POST[pnr]' OR name LIKE '$_POST[fnavn]' OR surname LIKE '$_POST[enavn]' ORDER BY surname, name ASC") OR DIE ( mysql_error() );

View Replies !
MySql Case Select
In my database i have some fields:

reg2year
reg5year
reg10year

i want to build a query that will select one of those fields according to a value that was posted from a form in a variable named: $regType.

View Replies !
MySQL - Select Question
Ive been fiddling around with a mysql query but cant get the result i want. Say i have the following table "orders":

OrderID OrderName OrderQty

1 apple 4
2 oranges 2
3 grapes 2
4 peaches 2
5 apple 6
6 peaches 3
7 bananna 2

I want to return the data like so:

apple 10
peaches 5
bananna 2
grapes 2
oranges 2

View Replies !
MySQL And SELECT FORM
PHP Code:

<?php
foreach ($_POST['farve'] as $key => $farve_output) {
    print $farve_output;
        echo ", ";
}

?>

<form method=POST>
<select name="farve[]" size=10 MULTIPLE>
<option>Grøn</option>
<option>Rød</option>
<option>Blå</option>
</select>
.......

View Replies !
Using PHP And MySQL To Populate (select) Menus
I am a newbie to php *gasp* and I am trying to make a <select> drop down menu, but I want the menus populated by information from a field in my database. There are a bunch of entries in the field MUD, that are identical......I would like the menu NOT to repeat identical names. EX... Each name only once, even though it is in the database many times.

View Replies !
MySQL: Insert...select - Update?
I was reading about insert select
http://dev.mysql.com/doc/mysql/en/insert-select.html

Thought this may be a better way to perform a query I'm doing. The differenc is that I need td select from one field, and then update another field in the same record (it is a backup/undo field).

Is there a way to do this in one query? It's a large chunk of data (longtext) so I thought this would be faster than the alternative...

View Replies !
Select List/Menu Using PHP And MYSQL
Here is my code:

<select name="country" class="sidelinks">
<?php
do
{
?>
<option value="<?php echo $row_AllCountries['country_ID']." ";?>"<?php if ($row_AllCountries['country_ID'] = $acountry) { echo "selected"; }?> >
<?php echo $row_AllCountries['countryname'];?></option>
<?php
}
while ($row_AllCountries = mysql_fetch_assoc($AllCountries));
?>
</select>

A few words to describe:
-$row_AllCountries['country_ID'](get from MySQL) is a unique country ID number
-$row_AllCountries['countryname'](get from MySQL) is the name of the country
-$acountry is the country ID number that i want to be selected when the form loads

I have all the values and country names named OK...the only problem is that when the form loads it selects the last country.

View Replies !
MySql Select Unique Rows?
I am have a table which contains recent search querys of another table.

I am tryng to output this data into a list so the user can click, and re-run a recent search...

The problem is that the table is full of duplicate searches from the same user.

How do I select the searches without retrieving duplicates?

SELECT id, term FROM project_term WHERE pid='$_SESSION[project_id]'

Also, would it make more sense to store all serches of a paricular user, or stop the insert if the record exists? Is there a way I can do this without performing 2 queries (ie adding some sort of LIMIT or other xeyword to the INSERT query?) I can't make the column unique because two users could perform the same search...

View Replies !
Mysql SELECT With (varchar) Variable
I have been sent from the mysql forum to here, apparently my problem is strictly PHP related? This one is easy I expect - I need to make a variable that is readable as varchar by mysql - I just think it will be faster to ask here than search all the PHP/MYSQL functions to get it right.

In my SELECT statement I would like to pass names (varchar in my database) via a variable called $membername e.g.: PHP Code:

View Replies !
[mysql] SELECT COUNT(*) Question
Is something like the following possible?

SELECT products.id, count(*) as counter FROM products, keywords WHERE
keywords.keyword in ("bla","hi","hello") AND counter > 2;

Can't get it to work :/

View Replies !
Select Count(*) Prblm With PHP & MySQL
I am trying to create a login script that will check to see if it is a valid user. I have tried two different ways but neither one seems to work. Here they are: Attempt #1

$connection = mysql_connect($host,$user,$pswd);
$result = mysql_db_query($db,$query,$connection);
$cntr = mysql_result($result,0);
if($result == 1)

This gives me this error:

Warning: Supplied argument is not a valid MySQL result resource in /home/lyates/gtstatskeeper-www/corecode/login.php on line 33

Attempt #2

$selectresult = mysql_query($query);
if(mysql_num_rows($selectresult) == 1)

This gives me this error:

Warning: Supplied argument is not a valid MySQL result resource in /home/lyates/gtstatskeeper-www/corecode/login.php on line 33

View Replies !
Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.

View Replies !
Select MySQL W/o Automatic Vars
I'm used to working on PHP4. This project is on PHP5, and they have the ability to automatically create variables from request parameters turned off.

So now it looks like I'm uable to select/print data from an MySQL database. I know this is probably very simple, but can someone point me in the right direction? Thanks! Here's my code I'm using: PHP Code:

View Replies !
MySQL - What Do I Need? GROUP BY? Nested SELECT?
I am stumped (or maybe just too durned
tired). Here's what I got...

CREATE TABLE `nodecat_map` (
`nodecat_id` mediumint(8) unsigned NOT NULL auto_increment,
`nodecat_cat_id` mediumint(8) unsigned NOT NULL default &#390;',
`nodecat_node_id` mediumint(8) unsigned NOT NULL default &#390;',
PRIMARY KEY (`nodecat_id`),
KEY `nodecat_cat_id` (`nodecat_cat_id`),
KEY `nodecat_node_id` (`nodecat_node_id`)
) TYPE=MyISAM;

CREATE TABLE `nodes` (
`node_id` mediumint(8) unsigned NOT NULL auto_increment,
`node_content_id` mediumint(8) unsigned NOT NULL default &#390;',
PRIMARY KEY (`node_id`),
KEY `node_content_id` (`node_content_id`)
) TYPE=MyISAM;

CREATE TABLE `text` (
`text_id` mediumint(8) unsigned NOT NULL auto_increment,
`text_content_id` mediumint(8) unsigned NOT NULL default &#390;',
`text_text` mediumtext NOT NULL default '',
`text_timestamp_dt` int(11) NOT NULL default &#390;',
PRIMARY KEY (`text_id`),
KEY `text_content_id` (`text_content_id`)
) TYPE=MyISAM;

Plus a 'CAT' table not shown, but referred to in NODECAT_MAP by
NODECAT_CAT_ID.

I don't want to spend too much time explaining how/why the tables are
organized like this, but here's a basic rundown of their
relationships:

1) NODECAT_MAP maps NODES to CATS (categories, basically folders),
with many NODES associated with a single CAT.

2) A NODE is basically a document whose content is stored in a TEXT
record, and in order to track multiple revisions of a NODE document
many TEXT records can be associated with a single NODE.

Here's what I CAN do ...

Given a CAT_ID (in this instance "5") I can successfully return all
records with the following query:

SELECT ncat.*, n.*, txt.*
FROM nodecat_map ncat
LEFT JOIN nodes n ON ncat.nodecat_node_id=n.node_id
LEFT JOIN text txt ON n.node_content_id=txt.text_content_id
WHERE ncat.nodecat_cat_id=5
ORDER BY ncat.nodecat_id DESC, txt.text_timestamp_dt DESC ;

View Replies !
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.

View Replies !
Select & Delete Mysql Queries
i've try to insert and delete record at the same page, but it only can insert and can't delete the record. when i click submit button from the previous form, the record is insert into table B and delete from the table A. is the code correct? Code:

View Replies !
Trick MySQL Select Problem
I have a database table, which has field that could contain a single integer
or a list of comma separated integers.

Is it possible to match each row of that field against an array of integers
and return those rows where any of the integers in that field are in my
array?

For example suppose I did the following:

arInts = array(2,4,6,8,10);

What I want to do is return all rows from my table where my field contains a
single integer and it is in my array, or where my field contains a list of
integers and any of those integers is in my array?

Is this possible and if so how do I do it?

View Replies !
How To Corret This Mysql Select Query?
I convert some code from access to mysql. And I have a InboxMessage
table which has From and To field.
So, the query is like:
select * from InboxMessage where To=12
12 is user id.
This query works fine in access. But does not work in Mysql.
I think the problem is the field To, which must be a keyword in mysql.
So, how to fix this? I don't want to change the field, becuase this
will need to change a lot of code.

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved