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




Creating A MySQL Table


I'm trying to create a table in PHP.  I can use phpmyadmin to do it but I can't create it in PHP.  I even copied the code generated in phpmyadmin and it still didn't work.  Here is the code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Creating Mysql Table
I have PHP script that creates a mysql table. My problem is when I goto the following php page to access the table it says "missing table 'table name'" I look in phpmyadmin and its clearly there. Eventually after refreshing the page like ten times it detects and works. Do I have to reconnect the mysql connection or something?

Creating Table Using PSP And MySQL
Ok, so Ive overcome the first hurdle of connecting to MySQL and MyDatabase on my
web server using PHP scripts. Now I want to create a simple table with 3
fields. Don't have a clue where to start using PHP.

Creating Table
There is much more to this script, but luckily that all works. The only part that doesn't work is the create table bit. When I simply name the new table such as 'local_school' it works fine and all the data is entered, but for some reason because the table anme  is a variable it refuses to create the table. I have checked the variable by echoing it and it works fine. Code:

Creating A New Table
$create_str = "CREATE TABLE $cat (item_id INT not null auto_increment primary key, image_URL text)";
$cre = mysql_query($create_str);

is there something wrong with my code, because it just doesn't create the table.

Creating A Calander Table From DB
I have a db with dates and menus for those dates. I want to put the data into a table with 5 columns (Monday-Friday). I can get them into a list. How do I get them formatted into a table so that the correct day is in the right column and such? Can I do it all in one quarry or will I have to do a quarry for each day or each week?

Also I want to print this table out. Is there a print page function in PHP?

Creating A Link Within Table Results?
I am using php and mysql. Does anyone have any pointers on how to include links within table results that point to additional information also pulled from the same db table?

I have some extensive info that I want to query. The intial results are going to be displayed in a simple wire frame html table layout. I would like each row to include a link that will take the reader to a more detailed version of the data for that particular row, and that more detailed data will of course come from the same db table. My problem is I don't know how to setup the code to create such link.

Creating An Array From An HTML Table
Before I try to do this myself (I remember doing it in Java years ago
and it was a pain)....

Has anyone run across a function that will take a string parameter
containing an HTML table, and return a 2-dimensional array with each
element corresponding to the contents of a table cell?

I see plenty of examples of doing the opposite: convert an array to
an HTML table. I want to go the other way, from an HTML table to an
array.



Creating Temporary Table From Full-text Query
i'm using a full-text search on my db which works fine, but now i'm working on filtering the results further, like products in range of prices. my logic is to simply SELECT them out of the temporary table, only if it would be created. i don't think i need to paste any code since i think you get the idea.

Creating Hyperlinks From Data Input To Be Display In Table
Ive used search functions and have found relevent thread but the coding does not match. I have a php page the displays records from a form. id  name, address, phone, website etc

I would like to make the website data to turn into a hyperlink once submitted. Here is my following php code that displays the table Code:

Grab Content From HTML Table And Place Into MySQL Table?
I am in the process of helping a co-worker upgrade some of his old static html pages into dynamic MySQL driven pages. He currently has a lot of pages with huge tables displaying data. Does anyone know if there is a script or class that can convert a table to a .sql file for upload?

Table Background Color Based On Results From MySQL Table
I am trying to get the "Did User Agree" field on a database query to be colored Green for "Agreed" Red for "Disagreed" and Blue for "Agreed (2nd Time)" .. I have my PHP setup to do the query just fine as of right now with alternating column colors, just can't seem to get the colors to work as I am hoping for.  Can anyone help me get the Agreed? table's background color to the colors above? Code:

Mysql Fetch_field Gets Table Alias, Not Real Table Name
After a SQL 'select .... from tablename alias'
the mysql_fetch_field function returns a value $result=>table which
will contain the alias, not the actual table name.
Is there a way to get the actual table name ?

I am running mysql 4.1 and php 4.4

Using PHP To Sort Data In MySQL Table 1 By Values In Table 2
I have a MySQL database with 2 tables in it. products and prices.. Products has a field in it called 'prodno'. Prices has a field in it called 'prodid'.

There is one of each item in products and each product has it's own unique 'prodno'

There are multiple instances of each product's pricing in prices.. One for each price.. So if a product had multiple prices depending on quantity it would have an entry for each price.. Example:

id = 1
prodid = 7001
qty = 300
price = 12.5

id = 2
prodid = 7001
qty = 400
price = 15.5

I was wondering if I could query the database getting info from the products table but sort it according to the prices in the prices table.

Kinda like doing a "SELECT * FROM products" ordering it by the lowest price value from each item..

This is all very confusing to me, and I'm the one writing it. Let's try one last time..

Query the database selecting * from products (I plan on using all the info in products) and ordering them by the lowest price for each item in the prices table. I've tried sorting the results of just a basic SELECT * FROM products using Javascript and PHP but with pagination in the results it makes it a bit hard.

Creating XML From Mysql
I am trying to pull data from an MYSQL table. Right now I am only getting the first record out because I am not using a check array. Here is my code, I have been bashing my brains in all day over this hopefully someon can shed some light on this. I tried a basic array earlier and it didn't work. Code:

Creating Table Rows For Ever Other Loop In A WHILE Loop
I'm trying to create a table using a MySQL fetch array while loop that would look like this:

CONTENT1     CONTENT2
CONTENT3     CONTENT4
CONTENT5     CONTENT6

I need a <TR></TR> for every other piece of content. But I don't know how to do this with a loop that uses a MySQL fetch array

while($row = mysql_fetch_array($result, MYSQL_ASSOC))

{
PHP CODE THAT IS LOOPED;};

I'm trying to remember from my old college Java class that we did something with loops for whenever the counter variable was even the loop would do something special... I don't know if this is possible with a while+mysql_fetch_array loop though.

Creating A New MySQL Database
I run a small horse racing based website that has a 'fantasy league' type competition each season. Last year i looked after all the entries, leaderboards etc.. using excel and copying and pasting to webpages each week.

However this year i am going to attempt to use MySQL and PHP to have it automatic bar result entry. I have built a basic php and MySQL site before with the usual insert, edit etc.. But this one will need features im not sure how i go about making.

Basically there will be a list of horses (around 150) divided into 4 grades. Entrants pick 2 horses from each grade so a total of 8 horses. Winning horses score 5, 2nd = 3 and 3rd =1.

I was thinking of having the following 2 tables - one for the horses - listing their name and grade. One for entrants - the peoples contact details and their chosen horses.

However from there im not sure how to able to enter the latest results and how i can create a leaderboard page and list the points each horse has. I was thinking of a new table with a row for each result showing horse name and points scored but i then dont't know how this table can be used to create a column on the horse table that lists each horses total points. And also how it can be used to create the total points each entranant has got so far (i.e. the total point for all 8 of their horses)

Creating Variable Using Mysql And Php
I am trying to create a variable but it just will not work. Anyone
see the error?

<?
$query = "SELECT Name FROM dataAA WHERE
NameId='".mysql_real_escape_string($_GET["Id"])."'";
$result = mysql_query($query)
or die ("no can do.");
while($row = mysql_fetch_array($result))
{

$Name = "echo $row["Name"]";
}
?>

Creating A Mysql Dbase Via Php?
I was wondering if anyone could tell/show me how to create a mysql database via a php script as my hosts do not support telnet(dont ask).

Creating A PHP/MYSQL Scheduler
I am trying to do is create a schedule that will block off times that are already booked, as well as color code a small calendar depending on whether there are AM or PM openings. I managed to create a working edition, but I took the easy route of making the time in 30min intervals and creating a column for each time (0800, 0830, 0900, etc) in the DB.

Now I need to create it allowing ANY time to be booked for ANY interval. I have an idea as to what needs to be done, I am just not sure how to go about doing it.

What I set-up was a table with the technicians names and times they can work that day. It simply had a column for name, column for start time (datetime field) and column for finish time (another datetime field).

Then I had a bookings table with many columns for different fields to do with the booking, but it also had a field for the name and start/finish datetime columns.

What I think I need to do is run a query first to grab the time range that someone is available that day. Format it somehow into a PHP array. Then look at the existing bookings and find the time free between the booking and the available hours using PHP. Display a color if there is availability in the AM, PM, or both.

Then I need to create an HTML table to display the bookings and free time based on the DB info to allow creation of new bookings. Can anyone provide some guidance who has done something similar or would know how to do it? I just need the base of finding the free time between bookings and available hours and displaying a table with such info.

PHP, MYSQL With Creating Waitlist
Would anyone have any suggestions as to how to set up a waitlist? Here is what I have:
A user goes on to my site and registers for workshop. They are offered a list of open workshops or they can be waitlisted for workshops that are full.  What would be the best way to structure this? I currently have 3 basic tables:

users
register (transaction info that connects users to workshop, has timestamp)
workshops (info about each workshop, date, time, cap, etc.)

My idea was to have an "order" field in the register table that would renumber itself every time someone registers or changes registration, but I am having difficulty with this renumbering. I was thinking I could use this order field to tell if someone's order has changed.  So for instance, I cap the workshop at 5 people, and 6 people are registered.  The 6th person is actually on a waiting list. 

Then someone drops out of the workshp and now that 6th person is the 5th person and is no longer on the wait list.  I could create some php code that said, if the person's old order field is 6 and the new order field is 5, then send an email "you are registered!"  That is what I am trying, but I am having difficult storing the old value and then renumbering and finding the new value.

Creating Link To From A Mysql Row...
I have the following code:

echo "<td>" . $row['title'] . "</td>";
I want it to link to $row['url'].

I have tried multiple methods, but I seem to be missing something.

MySQL Creating Links From Query
As I am still learning PHP could someone tell tell me how to achieve the following?

Display only the first four records from a sql query and have 'next page' links and number of pages so users can navigate the next four records and so on. The usual navigation you find on search engines.

I have the query and the num_rows function, I just need to know how to implement it.

Creating Search Engine In Php And Mysql
I want to create a search option for my site (ONLY searches my pages, NOT a web search).
A lot like the one on these forums actually. I was just wondering if anybody who has done this before had any suggestions as to how I should go about doing it.

Is it possible just using php and mysql... or would I need to use some other type of language (to make the spider). Or do I even NEED a spider for something like this?
Here is how I think it could be done. I'd have 2 columns. One for the location of each page on the site. Another would have text from the page (perhaps the first 40 words on the page).

From there, I could have my searching script compare the search value against anything the text column. if it found the search value in the text column it could display the link in the results page, with the text from the page to serve as a description.

Problems Creating Database MySQL In PHP
Hello, here is an interesting problem: I can connect to MySQL and create there normally databases via command line. The problem is when I want to create a database in PHP, I have problems apparently with the configuration of username and password in MySQL. I have PHP 4.3.9 as a module Apache2. and MySQL 4.1. I repeat, I can connect normally to MySQL in PHP, using mysql_connect() with the right hostname, username, password values. but when I write a script to create a database in PHP, it has these problems. This is the simple script:

Creating Directories From MySQL Query
I'm trying to create a subdirectory within a directory. The directory uses $rows['link'] from the category table, and the subdirectory uses $subcategory2 from the subcategory table. The directory that gets created is always based on the last record in the table, rather than the parent.

I have tried using another query, but only the subdirectory gets created then......

Creating A Tree And Storing It In MySQL
I'm wanting to create a tree structure and store this in a database, which can then be retrieved and displayed. I'm looking to implement this with PHP and MySQL. From what I gather it is possible using a table with two or three columns: ID, Parent_ID, Description.

So if we start from the top, the leaf would have an ID of 1, and a parent_id of 0. An item down the tree would have an ID of 2, and if a child of the first, a parent_id of 1, and so forth. How would I extract this from the database? Would I get all the data and then manipulate with PHP? Presumably I need to use some kind of recursion(another thing I'm a little shaky on).

PHP Code/libraries For Creating MySQL Databases
I am working on a registration system, and one of the things I am going to
need to be able to do it setup the database tables for each event that I
have registration for. Normally I would do this by hand, but I am wondering
if there are any code libraries out there that could generate the SQL for
me.

Basically I would have a list of column names and types. I know I could
just foreach() through the list, with a switch to divert control to the
different code segments depending on the column type, and at the end I would
have the SQL generated.

This seems like the sort of thing that somebody might have done before and
released a code snippet for. Maybe in PEAR DB? Any ideas?

Problem Creating A Mysql Database Named M#2 Using Php
I am serving a website using apache. All the php and mysql code I have
written works, except for one thing. When I try to create a database
named M#2 using the following call, no database is created.

$db = 'M#2'
$query = "create database '$db'";
$result = @mysql_query($query);

I am able to create a database just fine using this technique when it
is named other things (such as M$B, or Global1). I am able to create
the database using CocoaMySQL. The MySQL documentation I read says the
only characters you cannot use are , . / and , but they don't mention
"#". Also, it mentions that if you can have any database name that can
be used as a directory name. I am able to create a directory name in
unix called "M#2".

Creating .xls And .doc Files With Page Breaks Using PHP / MySQL
Our company currently processes a few hundred form submissions through
our site. Up till now, the contents of the form has been sent to our
customer support staff in real-time. Each submission goes to a general
e-mail box where it's printed through our mail client. A copy of the
form is also stored in a MySQL db, although it's not used that often.

I have been asked to figure out a way to stop delivering the form
submissions in real-time and migrate to the following:

Each morning, provide an Excel spreadsheet and word document (or PDF)
with a certain number of form submissions to each customer support
rep. For example, say 200 form submissions were processed the day
before. This morning, I should split those 200 among the 5 support
reps and provide each of them a certain amount (which can change
daily). Assuming each person gets 40 form submissions, each person
would need to be given an excel file and .doc document that contains
their 40 form submissions.

One of the most important things is that the .doc file needs to have
each form submission separated by a page break, so that when they
print the document each form submission is printed on a separate page.

Finally, not all of the fields from the form submission should be
given to the support rep. Maybe date and time is left off.

Help In Creating Data Entry Forms With MySQL
I was wondering if any of you experts has some example of MySQL data
entry form either using PHP or any public domain software for my photo
album. I'd like to enter some description with it.

From CSV To MySQL Table
I've a CSV file with 3 columns

ID - Price1 - Price2

How I would like to update the records of a MySQL tables that has the
same ID of the CSV files.

How Can I do this? Read from CSV and update MySQL table?

Exporting MySQL Table
Hi,

How do you export a MySQL table to a tab-delimited text file so I can put it into excel?

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.

How To Create A MySQL Table With PHP?
How to create a MySQL table with PHP?

Getting Mysql Table Info?
Suppose I have a table with name 'tablename' in my database.

If I have no idea what are the contents of this table, is it still possible to retrieve the structural info in this table, like the field names and sizes?

Get Max Value In MySQL Table Field
I have a 2-field table "pageref".

The fields are: "pagerefno" - which is index and primary key, and "url".

I need to find the max value in "pagerefno", so wrote the following code:

$query ="SELECT max(pagerefno) FROM pageref";
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
$row = mysql_fetch_row($result);
echo row[0];

But this results in a blank screen. I'd be grateful for a steer, here.

Search A MySQL Table
I want to create a php script to search a mySQL table. I started to create the script myself, but I got stuck, because the script became VERY complex. The reason why it's complex is this:

*the script must be able to search all four columns of the table.
if the user defines four different values to search (one for each type of variable (ie.: for each column)). If he doesn't give four values but by example only two, the script needs to search on these two values...

*the script needs to return all four values of all the rows that match the query

*the script may not return each result more than one time

*if possible, the script needs to return 'the best match' on top

examples:
consider a table with four columns:
animal_type |age | name | sex
horse | 5 |beauty| female
horse | 4 |bless |male
cat | 9 |***** |female

the query (horse,5,beauty,female) must return
horse | 5 |beauty| female (only one time!!! this sounds logic, but it isn't!!!)

the query(female) must return
horse | 5 |beauty| female
cat | 9 |***** |female

the query (horse, female) must return
1) horse | 5 |beauty| female
2) horse | 4 |bless |male
3) cat | 9 |***** |female
(number 1 must be on top; 2 and 3 may be changed of place, because they only match one variable!!)

PHP MySQL Updating Table Row
I have a small database of books that a client can add, search and edit (hopefully) books; all online (something very simple). So far I've been successful in creating the adding of books and searching and retrieving the info in fields to edit; but I haven't been able to execute the edits. Here's the script I have to retrieve the database info and place them in the fields to edit (I didn't copy all the mysql connection script, it works fine): PHP Code:

How To Get A Field In The Last Row Of Mysql Table.
There is a certain field that I wish to get in the last row (it will always be in the last row, even if I add to the table) of my mysql table. How do I output this? I assumed that I would be using a LIMIT command and a DESCRIBE command, however I looked at mysql.com and couldn't find anything .

Table Dump With MySQL
I have recently moved from a host that provided only 1 mySQL db, to a host that allows multiple db's. How do I dump a table, or tables from the single db...into a new db(s)?
I've used this before (to dump the entire db):

mysqldump -h mysite.com -q mysite_dbname > db_dump.sql -pmysitepassword

but I want to extract specific table(s) from the origian db and move them into newly created db's of their own on the new server.

Mysql Empty Table
does anyone know what the mysql comand to empty and table?

MySQL Table Create
Here is the code I'm trying to create the database with (I'm using phpMyAdmin so I just select the file I want to use and press submit and it creates the tables).

CREATE TABLE bips (
banned_ip varchar(15) NOT NULL);

CREATE TABLE messages (
entry_id double(16,4) DEFAULT &#390;.0000' NOT NULL auto_increment,
name varchar(25) NOT NULL,
email varchar(35) NOT NULL,
icq int(11) NOT NULL,
http varchar(50) NOT NULL,
message mediumtext NOT NULL,
when int(12) NOT NULL,
ip varchar(15) NOT NULL,
UNIQUE entry_id (entry_id),
PRIMARY KEY (entry_id));

------------------------
phpMyAdmin gives me an error with that, (none of those tables exists btw)... the error is

MySQL said: You have an error in your SQL syntax near 'when int(12) NOT NULL, ip varchar(15) NOT NULL, UNIQUE entry_id (entry_i' at line 8 .

Getting Mysql Table Size?
How would I go about getting the size of a table in a mysql database with php? I am unable to find info on this in the manual. Which page is it on?

PHP Variables From Mysql Table
I have a PHP script which parces a mySQL table and shows which
sections meet on which day by using an array containing (mon,...Fri)
and another lisitng sections. I then have the PHP do to selecrt
statements on to list those sections that are mixed and those that are
not.

I have a title "Open to Boys and Girls" then it cycles through the
applicable groups. I want to hide this title if there are no group
from the mysql search but can't figure out how as the actual varaible
$result is set once the search is done even if it pulls nothing back

Code is below,

CODE
-------------------------------------------
$result = @mysql_query("SELECT Group_Name FROM `groups` where
".$section."_comment like '%".$day."%' and ".$section."_comment like
'%mixed%'");
echo "<u>Open to Boys & Girls</u></br>";
while($row = mysql_fetch_array( $result )) {
$Group_Name = $row['Group_Name'];
echo "&bull; ".$Group_Name."</br>";
}// end Group Name loop mixed

Date Into Mysql Table?
how I can add a date to a mysql table with php? I am wanting to add the date when an article has been entered into the table.

Table Locking In MySQL
As there is no concept of Record locking in MySQL, Table has to be locked. If a Table is locked by one user, what happens to the other user who is accessing the table at that precise moment. Both are trying for a write access. What if the table is locked for more than a stipulated time. How should the script be written so that the other table who does not get write access waits.

Random Row From MySQL Table
I'm using PHP3, does anyone know how I can pull a random row from a mySQL table?

Make A Table In MySQL
How do I make a PHP script that is able to make tables with fields? I want to be able to have a HTML form submit the fields. I just want to know the PHP scriptlet that will make a table.

Create Mysql Table
I'm trying to create a mysql table in php. i have no problems doing a select, insert or anything else. i just don't know what the proper code is to create a table if it even exists.


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