You are here: Re: Creating tables on-the-run « PHP SQL « IT news, forums, messages
Re: Creating tables on-the-run

Posted by max on 08/14/05 01:48

[snip]
>And it would also help to see the content of $Query after assignment.
>
>This entire query is in wrong syntax. Have a look at CREATE TABLE in the mySQL manual.
I borrowed the output from phpMyAdmin. Just done it again, with a table
name of test, and it created a table called test, and returned -

CREATE TABLE `test` (
`id` SMALLINT( 3 ) NOT NULL AUTO_INCREMENT ,
`firstname` VARCHAR( 255 ) NOT NULL ,
PRIMARY KEY ( `id` )
);

and offered, under "Create PHP code" -

$sql = 'CREATE TABLE `test` ('
. ' `id` SMALLINT(3) NOT NULL AUTO_INCREMENT, '
. ' `firstname` VARCHAR(255) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ' )';
// What are the ' .' for; line-feeds in phpMyAdmin???

My whole file is -
<?
include("php-lib/connect_inc.php");
$TableName=rand(12345, 99999);
// which I thought would create $TableName with the value from the rand()

print("$TableName<br>");
//To check.

$Query = 'CREATE TABLE $TableName ('
. ' `id` SMALLINT(3) NOT NULL AUTO_INCREMENT, '
. ' `firstname` VARCHAR(255) NOT NULL,'
. ' PRIMARY KEY (`id`)'
. ' )';

$Result=mysql_db_Query ($DBName, $Query, $Link);
print("$Query<br>");
// To print out the $Query. The result of this is
========
24678
CREATE TABLE $TableName ( `id` SMALLINT(3) NOT NULL AUTO_INCREMENT,
`firstname` VARCHAR(255) NOT NULL, PRIMARY KEY (`id`) )

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
resource in blah-blah/create_dbase.php on line 21
====================

$Query="insert into $TableName (id, firstname) values ('5', 'Fred')";
$Result=mysql_db_Query ($DBName, $Query, $Link);
// to insert some test data

$Query="SELECT * FROM $TableName";
$Result=mysql_db_query ($DBName, $Query, $Link);
while ($Row=mysql_fetch_array ($Result))
{
print("<table><tr><td>");
print("$Row[id] $Row[firstname]");
print("</td></tr></table>");
}
// to select the test data and display it.
?>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация