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




Error In Generating Table From Database Select Statment


I am trying to dynamically create a table with the results from a select statement. Below is the code that is not working. Any help would be oh so greatly appreciated. This is for a final at school which is due in an hour. This is the only thing I can't seem to make work. Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
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 Statment
Is there a way to do something like this?

select x from y where z "starts with" abc

Begginer's Simple PHP Select Statment
my basic table connection syntaxt using PHP. I call
the php from a web browser url_name_goes_here/test.php. The database
name is tennis and the user name is tennis.

If I type the commands directly from the MySQL> mode, my access works
fine (see example 1 below). But when I try to access the table from
PHP, I have a syntaxt problem (see example 2 below). Can anyone
please type up the correct PHP syntaxt for me? The 3rd example works
but I don't know how to translate that into a select statement for the
table.

Finally, after I get it working, how do I keep my password out of
sight? if I forgot to put an index file in the directory, wouldln't all
of the files be visible from a surfer's browser? ...

If/Else Statment Within An Select/Option Group
I want to create an update query in a form so that I can update my groups attendance. The variables 100% are working and are pulling the correct info.  In the update attendance column, I would like an If else statement that says if the attend_status == present echo  SELECTED VALUE="", so that the pull down menu will display the current attendance value. From there I will select the new update attendance info and then submit it using an update query.

Below is the code. I am running into other problems with the quotation marks in such because this is all located within the <php> tags. Code:

Database P0c79 - Table Personaldetails Error
I can't create a table in my database. I get the following message: Database p0c79 - table personaldetails Error SQL-query:

CREATE TABLE personaldetails (id TINYINT not null AUTO_INCREMENT, firstname VARCHAR (15) not null , surname VARCHAR (15) not null , password VARCHAR (10) not null , teacherstatus ENUM not null , PRIMARY KEY (id))
MySQL said: You have an error in your SQL syntax near 'not null , PRIMARY KEY (id))' at line 1.

I can't see what is wrong with this - it looks perfect to me, and there is no room for error as all I am doing is ticking boxes in phpMyadmin.

Error Checking For Unique Value In Database Table?
I am inserting data into user table which contains 5 fields, sounds simple
enough normally but 2 of the fields are designated as UNIQUE. If someone
does enter a value which already exists, how do I capture this specific
error?

Would it make more sense to actually run a SELECT query first and if that
returned a result, then I use that for error checking and don't run insert
until select returns nothing?

Generating HTTP Header Error Codes
I'm having trouble generating HTTP header error codes which Apache will understand! My htaccess file contains: PHP Code:

What Is Indexing In Mysql And How It Will Be Useful And How We Can Retrieve Database Content Easily From A Database Table Containing About 5lakhs Datas
I need to select data from a database table containing huge amount of
data. Now I am storing data using one primary key and I am just using
simple select statement, and this process gives me the output but it is
taking long to execute the query. As much I had heared I want to use
some indexing or cluster indexing which might help me but I am not so
familiar with these things.

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

Merge Select From 2 Table
I've 2 tables where I want to retrieve the id and name from and merge them:

table1:
IDtable1-nametable1
1 - 578445
2 - 454545
3 - 554887

table2:
IDtable2-nametable2
X1 - 544512
X2 - 445775

The result should look like (order by nametable)
X2 - 445775
2 - 454545
X1 - 544512
3 - 554887
1 - 578445

(this result will be used for filling a combobox).
I may excecute 2 queries, put the results in an array and then order it, but
I'm sure there is a better way in MySQL, but I couldn't find it.

Select Country From Second Table
I have a form with a standard text box that i would like to turn into a drop down box that is populated from a mysql table. How do I change the code of the text box so that it looks at the table and populates the list?

Here is the code for the text box
<input type="text" name="country" size="20" maxlength="20">
The mysql table has the following fields in it:

Select * From Table When Field Is Less Than 3
i think it simple but i want to select all db entries where a certain field is less than 3?

Select From Table Where Field = String
How to select all lines containg a string (located in $pastmove) in the
moves column.

I tried several ways, for example:

$requete="SELECT moves, opening_id FROM suitemove where moves like
'%".$pastmove."%'";

but did not succeed;

SELECT * Form Table WHERE Function(??) BETWEEN ?? & ??
I have a CHAR(50) field in my table. This field stores datetimes in this format (i have no options to modify this stuff).
2001-02-16 00:00:00

Does anyone have an idea about how to make a function which allow me to:

- The user inputs two dates in 2 input boxes...like these:
2001/02/16 & 2001/06/14 (or maybe user inputs data like 2001-02-16 & 2001-06-14) (i must check with javascript how the data is entered and then parse the 2 input boxes).
Then i must list all data between 2001/02/16 & 2001/06/14 querying the table i told before.Does anyone have a good idea to do this?

Select Result On Empty Table?
can't remember how to do this, doing a select on a db like so.

$query = "SELECT user_id FROM tool_user WHERE user_name = '$user_name'";
$query = mysql_query($query) or die("eek");

which will work if there is at least one entry in the database table, however how do i return a result id the table is empty? do i need to use @mysql_query($query) and then something after that?

Select Table From Drop Down Menu
I'm trying to select a table to submit form data to from a pull down menu. How do I submit the table along with the input data? I know I need to modify this line ($sql = " INSERT INTO $dnc "; )somehow to use the table selected in the pulldown menu. Code:

Copy Select Records To New Table
In the table Step I have multiple records for each given id. I want to save the current list of records for an id to a new Step_Old table so I can look back at what I had at a given point in time, since the records for an id in the Step table will change over time.

Now the question... does anyone have a slick way to do this, or do I need to Select all the records I want to save and then save them one by one with a while loop into the Step_Old table?

Select DATETIME Table Row As Certain Format?
How do I select a DATETIME row from a MySQL table as a certain format?  Since in MySQL, it's displayed as 2007-05-25 13:44:00  How would I get it to display as May 25, 2007, 1:44 P.M.?

$news = mysql_query("SELECT newsID,posterID,headline,message,datetime as date(M j, o, g:i A) FROM news ORDER BY newsID DESC LIMIT 5") or die("Unable to connect to news database.");

How Do I Select The Last Field Of A Mysql Table ?
how do i select the last field of a mysql table ?

Not Sending Email After Select From Table
I want users who have forgotten their registration number to be able to input there email address and have the registration number sent to them.  My problem is if they have more than one registration number with the same email address it will only send one email from the first row it come to.  If they have 3 registration numbers in 3 rows I want them to receive all three numbers.  It would be 3 seperate emails. Code:

SELECT * FROM Table WHERE Column IS NOT NULL
I am running the following MySQL query:

<?php
$sql = mysql_query("SELECT * FROM comics WHERE story_arc IS NOT NULL") or die (mysql_error());
while($row = mysql_fetch_assoc($sql)) {
echo $row['title'];
}
?>

The problem is that it is outputting all 4000+ records, when it should only be about 100. Is there an error with my 'IS NOT NULL'?

Select SECOND Top Record In Table + Mysql
how to get second hightest record in table is there posible in mysql

Displaying SELECT Results In A Formatted Table
I was wondering how to show a table with a max limit of 20 results per page. I have various data being pulled and its putting it in a table, but its displayed all in one row. I want to format it so its a 4 column/5 row table. With that I then want the page to generate a numbered list at the bottom that calculates how many pages it takes to show 20 items on each. Code:

Store Result Of SELECT Stament To Be Used To UPDATE Another Table
im trying to update a field of a table which is done through the results of a select statement. I need to be able to a store the results of the select statement which can then be used to determine if an update another table is initiated. This is where i have got so far: Code:

Multi Table Insert Delete Select Function Needed.
I am going nuts here and I know with all the functions out there, there must be an easier way to do this. Maybe someone can point me to the right tutorial or even show me how to do this.

I have a $main_id and many $sub_id tables and like to “SELECT to view” INSERT and DELETE those. UPDATE must not be but would be nice.
Here is how it looks:

Select From Drop List To Fill Table Column With Text -- HOW ?
I want viewers to compare state laws on a single subject.

Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the column below.
The viewer can select states from the drop down lists above the other two
columns as well. If the viewer selects only one, only one column fills. If
the viewer selects two states, two columns fill. Etc.

I could, if appropriate, have a separate htm page with the text for each
state -- california.htm for example. When the viewer selects California from
the drop down list, the column below would "fill" with California.htm.

Or, I could conceivably use a text or mysql database with two fields for
each record: state_name and law_text -- but it would probably be easier to
use separate htm files, since there will only be about 20 states involved,
and the "database" would never have a large number of records.

The table width would be 100% and each cell would be @33%

My site is designed with FP 2002 and runs on Apache/FreeBSD. I have just had
Apache-ASP installed but I have not yet configured or used the module.

Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options.

I can't figure out how to get it work. Help is appreciated!!

function retrieve_category()
{
$cat = mysql_query("SELECT category_id FROM category");
while ($current_row = mysql_fetch_row($cat))
{
$row = $current_row[0];
if ($row == $id)
{
printf("<option selected>%s</option>
",$current_row[0]);
}
else
{
printf("<option>%s</option>
",$current_row[0]);
}
}
}

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?

Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?

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

Selective Echoing And Database Select
I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold.

The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated.

The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.

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.

Multiple Select From Database Where Clause
I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it.

I can get the list to display just the Aprilia category using the code below:

$data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc");

However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?

Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. 

I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image.  Can anyone help?  I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.

Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:

Phpgem Error In Select Count ?
I use phpgem to generate forms. it works fine, just one problem with count, I get error messages like this (from the php-script - NOT when i query mysql directly!):
SQL query: SELECT COUNT(*) FROM hupoterm WHERE (LOWER(gruppe) LIKE '%e%')
Warning: count not found in MySQL result index 2 in sql.php3 on line 255

Could this mean a problem with my table syntax? since 6 days i changed almost all config-parameters in the script, in the table ..... but the error message is still there .

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}

Connecting Two Database Populated Select Menus
I am able to grab the data from the database to populate the menus individually using.
PHP Code:

Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Soulbound
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = &#3962;'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

Reusing An Object For Common Select To Database
I've noticed that after I finished this app, I had repeated a similar task over and over and would like to modularize it. The repeated task was connecting to the database, executing a select, putting all the results of the columns into different variables of an object. PHP Code:

Simple Filter Of Database With $_GET And Select SQL
I need help with my logic statement with a simple search engine on a MySQL table.
I have three form text input fields named f_name, l_name and dept. I am using the GET method to gather data the user enters in each input field.

So far I have been able to build a check to see that the submit has been clicked but I am having trouble with assembling the SQL statement because I need for the search engine to be able to filter the results based on the information provided in 1-3 of the fields.

I could use if statements with some and clauses but that would mean that I would have to account for each combination. Something like

If(($_GET[‘f_name’] != “”) || ($_GET[‘l_name’] !=) || ($_GET[‘dept] !=)){

$sql = "SELECT * FROM facform WHERE f_name LIKE '$_GET[f_name]',
l_name LIKE '$_GET[‘l_name]', dept LIKE '$_GET[dept]' ”;}

The problem with this is that I would have to get every combination and it’s not very scalable. How can I create this SQL statement dynamically? Code:

Warning: Stream_select(): Unable To Select [0]: No Error In ...
<?php
while (true) {
$read = array(STDIN);
$write = $except = NULL;
if (stream_select($read, $write, $except, 0)) {
}
}
?>

When I run this in PHP4, I get a "warning: stream select(): unable to
select [0]: No error" error. In PHP5, I don't.

Error In Query: SELECT Uid, Uperms From Users WHERE Uname =
I am trying to set up the article from the main page in devshed called money is time
the thing is this, it denies access for this user and pass even though they are in the database 'example' and on table (users)

Error in query: SELECT uid, uperms from users WHERE uname = 'john' AND upass = PASSWORD('john'). Access denied for user: '@localhost' to database 'example' Code:

IF Statment
The following IF statement does NOT work properly, hehe, by that I mean it's supposed to inject the current date but it only injects a blank/null space. I've tried changing the statement in every way, including using different functions. The only way I've got this code to work is to put a die() at the end inside the IF.

<code>

if(isset($assignedto) != "Not Assigned Yet" && isset($dateassinged) == "") {

$today = date("ymd");
$sql = "UPDATE helpdesk SET dateassinged='$today' WHERE id=$id";
mysql_query($sql) or die("error");
//die(); If uncommented the date gets properly injected, but then the rest of the script doesn't get executed
}
</code>

The "dateassinged" column (I know its spelled wrong) is varchar(8). I've tried using type int but it still doesn't work.

Sql Statment
how would I right a mysql statement that would take a number listed in a database where userid == $userid and subtract &#391;' from it and then write that new total back to the database where userid == $userid

If Statment
I want to look in a DB table called 'Member' for the user session and look at a column named 'status'. If the 'status' column equals 'admin' I want to show a message, if the 'status' column does not equal 'admin' I want to show a different message.

I think I am on the right track but it's not working right. The user that I am looking up IS an 'admin' but this code is showing  'message for non-admin' instead of the admin message.

$sql = "SELECT status FROM Member WHERE loginName='{$_SESSION['MM_Username']}'";
if ($sql == "admin") {
echo 'message for admin';       
} else {
echo 'message for non-admin';
}


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