Page 1 of 1
New Question: Checking for a table
Posted: Sun Jun 20, 2004 2:12 pm
by XxLaSeRxX
Sorry guys Im really new to this. I did searches on google and found lots of stuff on how to create a table in my sql. Im trying to create a table yet its not working and Im getting an error
Code: Select all
<?php
$sql = "CREATE TABLE '$id' (username text(16),rating int(1));";
mysql_query($sql,$lk) or die(mysql_error());
?>
it says my syntax is wrong somehow.. I tried many variants of the create table command, and its still not working.. I know most of you will probably look at this code and just think "is he retarded?". Im sorry for that lol.
Thanks in advance.
Posted: Sun Jun 20, 2004 2:16 pm
by feyd
$sql= "CREATE TABLE `$id`(`username` varchar(16), `rating` int(1));";
try that..
Posted: Sun Jun 20, 2004 2:28 pm
by Buddha443556
No semicolon need in your query string. The type TEXT doesn't have any options, like length. The type INT is ok but you may consider using TINYINT to save space.
http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html
http://dev.mysql.com/doc/mysql/en/Numeric_types.html
Try this?
Code: Select all
$sql = "CREATE TABLE '$id' (username text, rating int(1))";
mysql_query($sql,$lk) or die(mysql_error());
probably look at this code and just think "is he retarded?"
Never crossed my mind.
Posted: Mon Jun 21, 2004 4:02 pm
by XxLaSeRxX
For some reason my code for checking if a table is in the database was working last night and stopped working today..
Code: Select all
<?php
$tExist = "SHOW TABLES LIKE '$id'";
if(mysql_query($tExist,$lk))
{
echo "Here are your ratings";
}
?>
For some reason this if statement is always true. Maybe my code is totally wrong but Im not sure..
Thanks
Posted: Mon Jun 21, 2004 4:22 pm
by feyd
uh.. you might want to check if any rows were returned.. the if just checks if mysql_query() succeded in running.. doesn't mean the table is used or not
Posted: Mon Jun 21, 2004 6:15 pm
by tim
Posted: Mon Jun 21, 2004 7:06 pm
by XxLaSeRxX
Im not checking if the table is being used.. I just want to check to see if the table is even there.
Posted: Mon Jun 21, 2004 7:19 pm
by feyd
if the table isn't there, you should get 0 rows back.
Posted: Mon Jun 21, 2004 11:14 pm
by XxLaSeRxX
I tried the num_rows command and it works but I am getting a warning.
Heres my code:
Code: Select all
<?php
$tExist = "SHOW TABLES LIKE '$id'";
//$tExist = "SELECT * FROM '$id'";
$temp = mysql_query($tExist,$lk);
if(mysql_num_rows($temp, $lk))
{
echo "Here are your ratings";
exit;
}
?>
the warning I am getting is:Warning: Wrong parameter count for mysql_num_rows() in \admin.php on line 23
I tried show and select, but gave errors.
Thanks,
Posted: Tue Jun 22, 2004 12:01 am
by kettle_drum
You dont need the $lk var in it, only the database result:
mysql_num_rows -- Get number of rows in result
Description
int mysql_num_rows ( resource result)