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.





SELECT * VS SELECT Field1, Field2, Field3


If I need all/almost all fields from a table, is there any significant performance difference between using SELECT * from table and SELECT field1, field2, field3 etc from table?




View Complete Forum Thread with Replies

Related Forum Messages:
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.

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

View Replies !
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 Replies !
SELECT From Results Of Previous SELECT. Possible?
Is it possible to do a SELECT on the database, then run another query on the results of the SELECT? e.g. From 100,000 rows I wish to SELECT 500.

From that 500, I want to do 10 SELECTs. I only ask because I assume that it will be a lot quicker to extract rows from the smaller "results" produced by the main SELECT than to run the 10 SELECTs on the main database.

Is this even possible? Or should I just do 10 SELECTs from the main database?

View Replies !
SELECT Within A SELECT And UNION
I'm really trying to wrap my brain around how this works...no such luck...I'll just break it out the way I started and see if somebody can help me see this one through...

What I'm doing here is querying two tables to retrieve three results - this works just fine. Then, as I loop through the results I make another query at each pass to retrieve img and content which are stored in the same table as the previous query.

Is there a way to combine all of this into one query? I've been messing with a SELECT within a SELECT and also UNION without any luck... Code:

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

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

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

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

View Replies !
Select From
Is there a way to select from multiple mysql tabels?

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

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

View Replies !
SELECT Url FROM
I have a fill in form where people can enter their address and dealer (reseller) in a text field I would like to redirect the visitor to the dealer-url when submitting the form, based on the dealer name they filled in. Code:

View Replies !
Select First 50
I need to be able to select a number of records in a table. I need to be able to select the first 50 in reverse chronilogical order (by order of date descending. I can easily select them all by reverse cronilogical order using

$query = "SELECT * FROM matches ORDER BY date DESC";

How can i select records 0-50?Or 50-100?

SELECT (first 50 by date) FROM matches BY date DESC

Is this possible or do I need to get the PHP to do this?

View Replies !
Select All
I want to select all from one table and just one item from another table. If I try to do the below it won't work. How can I do this?

SELECT * , buyers.buyer
LEFT JOIN buyers ON buyers.id = equipment.buyer
FROM equipment

View Replies !
More Than One Select
I wanted to create a form which will contains two select variables. eg Country and City

Both will be kept in two separate tables connected thru country code. The user had to select the country first. The list of the cities will depends on the country selected ie filtered by the country code.

View Replies !
Sol SELECT
$query = 'SELECT * FROM tablename WHERE columnname = "value" AND columnname = "anothervalue"'
now instead of a given name what is the correct syntax to use if the value must be a variable eg:
$var1 = $_REQUEST['var'];
$var2 = $_REQUEST['vars'];
$query = 'SELECT * FROM tablename WHERE columnname = "$var1" AND columnname = "$var2"'

tthe first statement no variables works not the second.

View Replies !
Select From Db
select from db where id = 3... if it doesn't exist, how can i display a message saying so. for example:

"3" is not a valid selection.

make sense?

View Replies !
Select Help
whats wrong with this code:

$sql = mysql_query("SELECT make, you, size FROM tablename WHERE make ='$carrymake' and location = 'loc' size= '$size and price >= '$miniprice' <= '$maxiprice' LIMIT $from, $max_results");

View Replies !
Sql Select Where
PHP Code:

$sql = "SELECT count(*) FROM $app$LISTINGS WHERE TITLE LIKE '%$_POST[search]%' OR SUMMARY LIKE '%$_POST[search]%'";

This works fine except for when somone enters more then one word. it tries to match the exact phrase.

I want to pull results from any words in a phrase, not the exact phrase - not quite sure how to go abouts accomplishing this.

View Replies !
Using SELECT
I am developing a form that allows the user to enter data and upon submission, checks various databases, returns the data to the user so they can confirm before submission to the database. Two of the fields are employee names which are retrieved via a call to
the db:

<TD>Assign Rep/Mfg Hours To</TD>
<TD>
<SELECT NAME=arht>
<?
while ($myrow = mysql_fetch_array($emplist1)){
$arht=$myrow['lname'].", ".$myrow['fname'];
echo "<OPTION VALUE=$arht>$arht</OPTION>";
} ?>
</SELECT>
</TD>

As you can see, the field is built by concactinating the lname and fname fields. Once the FIRST submission button is clicked, I redisplay the form with the values the user entered and the returned values from various db searches that are performed.

View Replies !
The Select Box
When the page is load. I want that the current week will be seen on the select box.

<select name="starts" class='dtext'>
<?for ($i = 1; $i <= 60; $i++) {
$start = weekDayToTime($i, 2007);
echo "<option value='$i'>" . date("d/m/Y", $start) . "</option> ";
}
?>
</select>
<select name="ends" class='dtext'>
<? for ($i = 1; $i <= 60; $i++) {
$start = weekDayToTime($i, 2007);
$end = cleanTime(604800 + $start);
echo "<option value='$i'>" . date("d/m/Y", $end) . "</option>";
}
?>

View Replies !
Select From Pos 0 To ':'
I have a variable $var that is like that :

$var = blah.blah...: blibli bli bli...

I 'd like to select only the part of my $var before the ":". This part could have a different size. I don't know how to do that in php.

View Replies !
Select Only First Row
I have a SELECT query that returns many rows for one item. I want to display the item once, and then loop through all the rows to build my option dropdown. I know how to do all of this EXCEPT for how to get only one row to display the item in the first place. How do you get one row out of the result:

else if ($item != "") {
while ($row = mysql_fetch_array ($itemresult))
{
if (($row['ITEM_NO'] == $item)){
echo $row[0];
$title = $row['ITEM_NO'] . " " . $row['DESCR'];
$item_block .= "<td><center><img src="" . $item_dir . "/" . mb_strtolower($row['IMG']) . "" alt="" . $row['ITEM_NO'] . "" /><br>" . "$" . $row['PRC_1'] . "<br>" . $row['ITEM_NO'] . "</center><br>";
$item_block .= $row['HTML'] . "</td>";

View Replies !
Use 'if' To See If SELECT
I'm trying to develop a piece of code along the line of:

$query3 = "SELECT.......
$result3 = mysql_query($query3)
or die ("Couldn't execute query.");

if ($result3 IS NOT NULL )

{echo "<h1>Results</h1>....etc
}

In other words, I'm trying to generate an IF statement that only processes the conditional statements if the SELECT query returned at least one result. What is suitable syntax for seeing if $result3 contains any data (the writing in red)? I know how to tell is an individual string is null, but is there a quick way of seeing if an entire array is null?

View Replies !
SELECT WHERE (OR) WHERE..
Id like to select results from my database where (whatever) = (whatever) OR (somthing else) = (somthing else)

I am getting peculiar results, how would I write this?

SELECT * from TABLE WHERE whatever='$whatever' OR WHERE somthingelse = '$somthingelse'

View Replies !
SELECT FROM , WHERE
I'm really in a dreadfull situation. i got my submissions tomorrow. and my brain seems to be off now. i have a database called test and table called user. user table has all possible stuff like userid, username, upass, fname and etc. i need to use SELECT query to display userid in one corner, fname in other. how do i do this.

View Replies !
Select From Where IS NOT?
Is their a way a can use somthing that WILL NOT return result's from mysql. for example.
if i wanted to display rating's of articles that where the highest , but NOT rated a perfect 10. Is their a SQL IS Not statement?

View Replies !
SELECT Last Row WHERE ___
Lets say you have the table columns:

ID
FOREIGN_ID
NAME
TIMESTAMP

The table would have multiple rows for a FOREIGN_ID. What would the query be to SELECT the last row for a FOREIGN_ID? Or, what would it be for a FOREIGN_ID's latest TIMESTAMP?

View Replies !
<select> Value
I have a script which let the user choose between four days :

Day: <select name="day" value="$day">
<option value="01">1</option>
<option value="02">2</option>
<option value="03">3</option>
<option value="04">4</option>
</select>

The selected number is saved in mysql database. I have also a script which alows the user to edit their choises. The problem is that I don't know how to set the value from the database into the select thingy. I know how to handel this with an:

<input type="text" name="title" value=$somvar >

But how can I do this with the select thingy ?

View Replies !
Select For DB
I making this script or w/e and the user checks wut he wants included in the text file how can i make it so you can slect info from the db and make it a txt file.

View Replies !
Can SELECT MAX Be Used With WHERE ?
I was wondering if this is correct :

$query_max = "SELECT MAX(ima_rank) AS ima_rank FROM image WHERE sec_id='$sec_id'";

the problem is that it returns the highest value in the ima_rank column but not the highest rank with a specific sec_id

if that's not correct what would you suggest ?

View Replies !
Select A Particular Row Or By ID
How do you select a mysql database base on what row number it is. For example I want to select row number 24 in the database.

View Replies !
CSS Select
i want to select a certain css file depending on the browser. the code works fine IE6 IE7 and all mozilla versions. but it has issues in safari? i dont know whats wrong here, can anyone help by suggesting a working code.

View Replies !
Select From Where OR
PHP Code:

$sqlClistings = "SELECT count(*) FROM $table2 WHERE
CATEGORY = '$row[ID]' OR WHERE
CATEGORY2 = '$row[ID]' OR WHERE
CATEGORY3 = '$row[ID]' OR WHERE
CATEGORY4 = '$row[ID]'";
$resClistings = mysql_query($sqlClistings);
$rowClistings = mysql_fetch_row($resClistings);

View Replies !
SELECT Within SELECT
I know this is strictly not PHP, but I'm using PHP to access a MySQL database, and I'm sure other PHP programmers will know how to fix my query here, and there didn't seem to be a MySql section.

Anyway, it's a simple enough join question, but I've never understood them. MANY years ago, someone showed me how to do this without joins, and I would be much appreciative if someone could show me again ;^) Code:

View Replies !
Select
I have a database which has a mebers table In that table is a field for members location... When a member logs in I want it to display 50 people who are from the same location from them

However, a few locations only have 20 members or so from them and I must generate 50 profiles It would be ok to have a list of 20 then 30 random ones..

How could I perform this search in 1 query? Basically find the first 50 matches for the location and if cant find 50 match just display any location for the next 30..

View Replies !
Select Max()
<?
mysql_connect("localhost","name","pass");
mysql_select_db("MyDatabase");
$result = mysql_query("SELECT MAX(count_visits) FROM artist");
//grab all the content
while($r=mysql_fetch_array($result))
{
$profile_views=$r["count_visits"];
//display the row
echo "<FONT size=2><center><font color=#000000>Profile Views: $profile_views</font></center>";
}
?>

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

View Replies !
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);
?>

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

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

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

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

View Replies !
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");

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

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

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

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

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

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

View Replies !

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