Current location: Hot Scripts Forums » Programming Languages » PHP » if table exists do "this", if not, skip "this"


if table exists do "this", if not, skip "this"

Reply
  #1 (permalink)  
Old 09-28-06, 07:24 AM
Deansatch Deansatch is offline
Coding Addict
 
Join Date: Jul 2006
Location: Northumberland
Posts: 375
Thanks: 0
Thanked 0 Times in 0 Posts
Angry if table exists do "this", if not, skip "this"

I have a little problem. I have some code that works great, but when the user deletes a certain item from another part of my site he automatically deletes the table used in this script until he assigns a new table to it.
So, basically I want the script to run only when the table it asks for is present and if it is not present I just want it to ignore this part of the script and carry on with the rest of the page.

PHP Code:

$connection mysql_connect($host,$usr,$pwd);

$getcontent mysql_db_query($db"SELECT * from table_home where id='1'"$connection);
$row mysql_fetch_array($getcontent);
$gigid $row["gigid"];

if (
$gigid >=){
$todaysdate date("Y-m-d");

$connection mysql_connect($host,$usr,$pwd);
$getcontent mysql_db_query($db"SELECT * from table_$gigid WHERE date >= '$todaysdate' ORDER BY date asc"$connection)or die(mysql_error());
$row mysql_fetch_array($getcontent);
$date $row["date"];
$date1 date("l dS F Y"strtotime($date) );
$venue $row["venue"];
$address $row["address"];
$time $row["time"];
$tickets $row["tickets"];
if (
$date >= $todaysdate ){


$filename "nextgig.html"
$handle fopen ($filename"r"); 
$contents fread ($handlefilesize ($filename));
$contents str_replace(XdateX$date1$contents);
$contents str_replace(XvenueX$venue$contents);
$contents str_replace(XaddressX$address$contents);
$contents str_replace(XtimeX$time$contents);
$contents str_replace(XticketsX$tickets$contents);
fclose ($handle); 
print(
$contents); 
}

basically I want to add something like "if table_$gigid exists" after "if ($gigid >=1 )"

any ideas??
__________________
Aye!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-28-06, 08:33 AM
mab's Avatar
mab mab is offline
Community VIP
 
Join Date: Oct 2005
Location: Denver, Co. USA
Posts: 2,674
Thanks: 0
Thanked 0 Times in 0 Posts
Try something like this -
PHP Code:

$query "EXPLAIN table_$gigid";

$result = @mysql_query($query);
if (
$result){
echo 
"table exists code here";
} else {
echo 
"table does not exist code here";

__________________
Error checking, error reporting, and error recovery. If your code does not have these to get it to tell you why it is not working, what makes you think someone in a programming forum will be able to tell you why it is not working???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Pretty simple ( i think) question any help!?!? 0o0o0 PHP 2 04-07-06 11:47 AM
Querying a table based on phpBB2's usergroup table Venthos PHP 1 09-01-05 02:42 PM
Problem with a sort table js function tdubyou JavaScript 0 05-03-04 10:19 AM
auto table resize derick_2k JavaScript 4 04-26-04 03:32 PM
Newbie MySQL fccolon PHP 2 03-16-04 11:54 AM


All times are GMT -5. The time now is 07:07 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.