re

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

re

Post by pb2ya »

not if there is tables, but if a certain table exists, like how do you see if theres a table named _topic1 in the database?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

the reply to your last post provided a solution to your question. that function will give you a list of tables and all you have to do is find out if the one in question is in that list.
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

lol

Post by pb2ya »

how about you give me an if() statement to see if a table called _table exists. if it does exist, $x = 1. if no, $x = 0. just give me tha code, thx ;D
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

im going to assume you are very new to php and therefore do not have much experience in doing a little research in the manual. thats fine but try to keep in mind for the future, we are here to help you, not to code your problems away. i have gained and provided much help here and i hope you will in the future.

with that said here is a script that should help you out. i have left it up to you to deal with the part indicated in the if statement:

Code: Select all

<?php
//assume connection is already open using mysql_connect()
$table = "my_lost_table";

$result = mysql_list_tables("mydmnsn");

$num = mysql_num_rows($result);

for ($i = 0; $i < $num; $i++) {
    if ($table == mysql_result($result, $i, 0)) {
        //the table was found, now do something with it
        print "$table found at index $i";
        break;
    }
}
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Re: lol

Post by twigletmac »

pb2ya wrote:how about you give me an if() statement to see if a table called _table exists. if it does exist, $x = 1. if no, $x = 0. just give me tha code, thx ;D
How about you do your own work? mydimension was very kind in giving you an answer which you really didn't deserve. This is not a script writing service and if in the future you can't be bothered to actually put suggestions into practise I suggest that you go to the Jobs Forum and hire someone to do the work for you.

Mac
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

thank you mac :)
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

:)

Post by pb2ya »

ok thx, im new to php, and thx again.
BTW- im NEVER gonna hire some1 for work i can do mahself. ok that was hypocritical kinda :lol: . anyways, the php.net manual was down, and mah php book didnt help either, thx anyways for the critisicm.
plz excuse mah spelling. hope phpbb3.0 has spell chack :D
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Re: :)

Post by hob_goblin »

pb2ya wrote:plz excuse mah spelling. hope phpbb3.0 has spell chack :D
No offense, but I think you'd probably break it.
Post Reply