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




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?




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.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

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.

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.

Get A Value From Select Box
I am having difficulties getting the current value of a select box to pass to a function Code:

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=&#390;'";
// 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=&#3995;%'>";
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?

How Do You Select Everything After A Certain Date Please?
I want to select records from a MySQL database using PHP. I want to select all the records after 30th September. How do I do this, please?

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...

Select Data From Db?
I have a db that I need to select data out of. In the field it is selecting out of there is data input there from an array and then implode is used to seperate each item with a, When I run a query and wanna select data from this row I need the data from the previous form to = only one of the items in the row, but could be any of the items. how do I tell the page or the query that it could be any of many things in the row, but only has to be equal to one of them?

Using RAND() To Do A Select
having problems using the RAND() function in my mysql queries from php and can't figure out whats going on.

"SELECT id FROM work WHERE active = 'yes' ORDER BY RAND() LIMIT 1"

bascially it always seems to be picking the first entry from the database we'll say 8 times out of 10 out of a possible 20 results which does'nt seem very random to me??
is RAND() truely random? or are my page headers which are making sure the page does'nt cache interfering with this?

//header makes sure it refreshes
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");

Html Select W/php
I am just trying to have and html select and pass the $post to php page. This is what happens: html snippet:

<form method="POST" action="./phphandler.php">
<select name="thisname" id="thisname">
<option value="thisvalue1">thisvalue1</option>
<option value="thisvalue2">thisvalue2</option>
</select>
</form>

php snippet:

<?php
$thisvar=$_POST['thisname'];
print "$thisvar";?>

Result:
thisvalue1thisname=thisvalue1

Select Box Question
I have a database table with abut 200 entries. On a page, you can select one of these entries via a select box. I use a while loop to populate the select options, the variables look like this...$last_name, $first_name- In the select box before any of the names, all you can see is the comma. Then you see all the names: Margo, Jenny etc.

Is this how it should be? Is there anyway to put 'Select Person' in place of the comma? There are no empty rows in the table so that's why I'm a bit confused.

SELECT INTO OUTFILE
I am having trouble with this function, it is designed to dump some information into text file before a record is deleted. Code:

Select Options
I am trying to pass some 'on the fly' list contents to a php handler script. The lists are created using JScript and I want to know how to get the value of the contents (not just the selected ones, but ALL the contents).

PDO::prepare And SELECT WHERE LIKE
I'm trying to get the following code to work:

$sql = 'SELECT name FROM ' . DB_TABLE_CITY . ' WHERE country_id = :countryId
AND name LIKE ":city%" LIMIT 10'
$sth = $dbh->prepare( $sql );
etc...

Select Problem
I am building an administration page and am currently designing the edit articles page. I have different input boxes and textarea's here and there for the different things, such as title, main and intro.

But i have a problem now, i want to use a <select> tag to select an array of users that i have in a MySQL database, and when i go to edit the record, i want it to automatically select the <option> that the record corresponds to. Code:

Php/mysql Select
I need to retrieve the most recent additions to a table where column name='$string'
My question is that of these records returned, I need to diplay THE MOST RECENT record in one place on the html page, and then display the others (in order from newest to oldest) in another place...

I can pull the records with a select statment, and I understand the ORDER BY statement that follows, but how do I split the results as above?

** The records have a 'date/time' column, and a 'category' column that I will use to perform the select statement...**

Variable In Select Row
I want to Select a field based upon the number the user keys in I want to
retrieve another field from the same record

This is not working. How do I do it? The tricky bit seems to me to be
putting the variavble in the select quotes.

$scfchknum=$_POST['scfchknum'];
(inlogging mysql)
$upgcollect='SELECT scfpwd1 FROM scfmforening WHERE scfmnum = $scfchknum'
(logout mysql)
$pwd1=mysql_query($upgcollect);
mysql_close();
echo $pwd1;

$scfchknum is the value of the variable assign to user input
scfmforening is the name of the table
scfmnum is the name of the field I want to search in
scfpwd1 is name of the field I want to retreive from
$upgcollect is the data before it is processed with query
$pwd1 is the data after it is processed.

Php Select Search
I want to have 2 html select boxes and be able to do a search to a sql database depending on the two selections....

Select List
I'm creating a form that has three select lists. The first one has two values EMAIL and SMS. What I want to do is have the two other select lists (named EMAIL and SMS) work so that if EMAIL is selected only e-mail select list can be altered and vice versa with the SMS.

How can I do this? I know to use disabled in <select> -tag, but how can I check the what the value is (and the value changes) and then act acording to it?

MySQL SELECT
I have a page where I am trying to list data from a select statement. However, I am only getting one record from this SQL statement in a PHP script, but over 3200 records with the same statement in phpMyAdmin. Am I doing something wrong? PHP Code:

Mysql_query SELECT
I have a table called file that has the following columns Code:

id tinyint(10) auto_increment
code varchar(9)
filename varchar(30)
ip varchar(16)
expires datetime

Everynow and then (for some unknown reason) the expires column gets 0000-00-00 00:00:00 instead of a real datetime 2002-07-02 00:56:18

I want to run a query that checks to see if there is a valid datetime before the script goes on. Rows will be added and deleted on the fly by user interaction. What is the best way of doing this? PHP Code:

If - ElseIf - SQL Select... ASP YES.. PHP NO?
I have a form with 2 fields.
'A'
'B'

The user completes one of the fields and the form is submitted.

On the results page I want to run a query, but this will change
subject to which field is completed.

In ASP I can use:

queryA = request.querystring("A")
queryB = request.querystring("B")

If QueryA <>"" then
SQL STATEMENT

Elseif QueryB <> then
ANOTHER SQL STATEMENT

End If


The pages checks for a value in QueryA or QueryB then creates the
correct SQL Statement..

How do I do this in PHP ?

Problem With My SELECT
I have a page with a link

<a href="Contributor.php?action=&SubCat=<?php echo $row["writer"];
?>"><?php echo $row["writer"];?></a>

that does to a page with a SELECT

$query = "SELECT * FROM news WHERE writer='$SubCat' ";

But it is not pulling any data from the database. If I do this
$query = "SELECT * FROM news WHERE writer='Bob Smith' ";
works great??

also
the ULR reads -
Contributor.php?action=&SubCat=Bob%20Smith
so I know the link is correct ....

but for the life of me I can't figure out whats wrong with the SELECT
statement?

here is the complete Contributor.php script.

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><!--
#BeginTemplate "/Templates/journ.dwt" -->
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
<!-- #BeginEditable "doctitle" -->
<title>paper</title>
<!-- #EndEditable -->
<link rel="stylesheet" href="Styles/template.css" type="text/css" />
</head>
<body>

<div id="container">
<div id="logo"><img src="Images/logo.jpg" border="0"
alt="logo"></div>
<div id=bar><form action="a.php" method="POST">
<label for="searchtxt">Search our archives:</label>
<input id="searchtxt" type="text" name="searchtxt" value="" />
<input class="button" type="submit" value="Search" /></form>
</div>
<div id="header">
<!-- #BeginEditable "Adds" --><div
id="athlete"><img
src="../Images/Athlete.gif" border="0" alt="AthleteMonth">
<img src="../Images/AthleteMonth.jpg"
border="0"
alt="AthleteMonth"><br>
Susan smith</div>
<br>
<? include("Ads.php") ?><!--
#EndEditable -->
</div>
<div id="sidebar">

What Is Quicker As Select?
I read somewhere that to gain efficiency it is advisable to avoid the
use of select. But they don't explain why or what to use instead. Is it
true? I habe a problem of speed (better to say of NO SPEED) but I don't
know if it has something to do with the use of select.
Waht can I use instead?

Form Select
I have a drop down in a form, and it want to make it so that when a selection is made, the same page is called and gives another drop down menu depending on what they have chosen in the 1st drop down. How can I do this? I used th onchange method, but I don't know how to pass the selected value from the drop down.

Problem With Select...
I've got a form with a select list:
<select name="$dane[$idhotelu][$pomocnicza][$k]">;

After "submit"
$_POST['$dane'][$idhotelu][$pomocnicza][$k] contains the selected value -
Am I right??

I have a problem ith this code:

echo"<select name="$dane[$idhotelu][$pomocnicza][$k]">";

for($i=0;$i<=$nrooms;$i++)
{
echo "<option value="$i"";
if($POST['$dane'][$idhotelu][$pomocnicza][$k]==$i){
echo" selected>$i</option>
";
}
else {
echo">$i</option>
";
}//endif
}//endfor
echo"</select>";

Even if I do something like this:
$dane[1][$pomocnicza][0]=1

This seems to be true for $i=0:
if($POST['$dane'][1][$pomocnicza][0]==$i){

"if" condition is true for $i=0 I have no idea why...
Is it because after submit form is reloaded?

Two Tables, Same Value, Same Select?
I have a two lists of people, (name) in two tables, and I want to give a bit long list of all these people. Below I have my current code, but its useless because its one list split in two, half way down you hit the As and Bs again! Code:

PHP And SELECT Box Issues
I have an input form for which I've created a "matrix" for user input.
Basically, the user chooses a radio button and then through javascript, a
select box is displayed to define a value for that radio option, like so:

Choice: (Radio1) type: (select box1)
Choice: (Radio1) type: (select box2)
Choice: (Radio1) type: (select box3)
Choice: (Radio1) type: (select box4)
Choice: (Radio1) type: (select box5)

I know, it looks confusing and is ;)

Now the problem is weird:

After a record is stored, I want to also pull out the data and repopulate
this form with it. I've used the "checked" attribute to define the correct
radio button, and the "selected" attribute to define the selected dropdown
value. This works properly and appears in my HTML properly however when I
make a new choice in the drop-down select box, the value designated as
"selected" always takes precedence when the form is posted.

I really need the user to be able to modify the selct box for the radio
button that has been checked, or to pick a new radio button and then choose
options from that associated select box. For the sake of orderly
presentation, this is the easiest method I have found but for PHP, I need
to override the "selected" value if something new has been chosen.

To clarify a bit further, here's an example of the HTML to visualize
things:

<html>
<head>
<title>Select Box problem example.</title><meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--
function hide(id){
if (document.getElementById && document.createTextNode){
spans=document.getElementById
('mainform').getElementsByTagName('span');
m=document.getElementById('mainform');
for (i=0;i<spans.length;i++){
m.getElementsByTagName('span')
[i].style.visibility='hidden'
m.getElementsByTagName('p')
[i].style.background='#eee'
m.getElementsByTagName('p')
[i].style.borderColor='#ccc'
}
if(id!='none'){
m.getElementsByTagName('span')
[id].style.visibility='visible'
m.getElementsByTagName('p')
[id].style.background='#ffc'
m.getElementsByTagName('p')[id].style.borderColor='#
000'
}
}
}

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?

While, Foreach And Select
there ive trying to make a game based on php and currently ive some problems with this part of the script, i've tryed to fix it alone with out
success...

This is the script:

<?php
include("db.php");
include("debug.php");
set_time_limit(0);
dbConnect("sessions");
$sqlUID = "SELECT UserID FROM Star_USER";
$UsersID = mysql_query($sqlUID) or die("Query failed");
while ($UserID = mysql_fetch_array($UsersID,MYSQL_ASSOC)) {
foreach ($UserID as $UID){
$sqlSz = "SELECT Size FROM Star_USER WHERE UserID = '$UID'";
$UserSize = mysql_query($sqlSz);
$OldUS = mysql_fetch_array($UserSize);
$AKA=$OldUS[0]
$UpdateSTR = mysql_query("UPDATE Star_USER SET NW='$AKA' WHERE
UserID='$UID'");
}
}
?>

What i wanted is that each time i run the script it will update the NW field
in the database based on the size of the player and this for each one of
them.

It all works if i take the select statment from inside the foreach, but i
need him there soo i can have the size of the player.

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?

Populating A Select Box
What I want to do for members of my website is to allow them to click a button that will add their name to a list that populates a select box.  I can do this on my own, but I was curious if I have to use a database in order for this to be possible. 

Drop Down Select
I am working on a small script to load all members names into a drop down list, this I have acheived so far. What i'm looking to do is make this so that when I select a name from the list I have a submit button which opens up a member edit form which I have created. Code:

Randomly Select A Row
I have to do a script where a user fights an enemy. There are many to choose from all for differn't levels in which the user is at.

I need to first (SELECT * FROM creep_data WHERE minlvl < '".$user[lvl]."' AND maxlvl > '".$user['lvl']."'")

After I have all of the possible monsters I need to randomly select one of these and retrieve all of the data about it.

How could I go about doing this ?

SELECT MAX(id) Not Working!
I have a table with a bunch of tutorials.  id is a field that holds a unique id.  Very simple!  I started off using a count to get the next id, i.e. count all the tutorials in the table and then, nextId = count + 1 kind of thing.

This was fine until I discovered some tutorials may need to be deleted so if i deleted number 2 and then tried to add one, it would have the same id as the one before this one was entered.  i.e. 2 tutorials with the an id of 6 like is happening at the minute. I want to use the SELECT MAX statement but it's not working for me.  Here's what I have so far. Code:

SELECT And SUM Function
I am trying to get the SELECT and SUM function to work.  I would like a column to add all the numbers in the column and get a total.  If a user trys to update the table and that total is at a pre determined number it will echo one thing if not it will echo something else. Code:

Select All Button
For my site inbox i have a load of checkboxes besides each message to select then press delete , but i was wanting to place a "Select All" button besides the delete button to have all the boxes checked at the 1 time but not sure how to go about it Code:


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