MasterACE14 Posted December 1, 2007 Share Posted December 1, 2007 Evening PHP Freaks, I am making a basic function which checks whether a column is in table 1, or table 2. All is going good except for the last part. I'm stuck at the finish line lol. Here is what I got, and I would appreciate it if someone would be able to do the rest of it, I'm just lost now. :-\ <?php // Check if the column in the database is in 1 table or another function wheres_column($column) { // Your two queries... $first = "SHOW COLUMNS * FROM `cf_users`"; $second = "SHOW COLUMNS * FROM `cf_users2`"; // Start query one $result = mysql_query($first); // Debug... if(!$result){ die('There was an error.'); } // Start loop while($row = mysql_fetch_assoc($result)) { if( } }; ?> Regards ACE Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 Remove the *'s from your querys PhREEEk Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 here's a general purpose column name finder <?php $host = '****'; $usr = '****'; $pwd = '****'; $dbname = 'test'; mysql_connect ($host,$usr,$pwd); mysql_select_db($dbname); if (isset($_GET['column'])) { $ta = wherecolumn($_GET['column']); echo '<pre>', print_r($ta, true), '</pre>'; } function wherecolumn($column) { $sql = "SELECT C.TABLE_NAME FROM information_schema.`COLUMNS` C WHERE C.TABLE_SCHEMA=DATABASE() AND C.COLUMN_NAME='$column'"; $tables = array(); $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>"); while ($row = mysql_fetch_row($res)) { $tables[] = $row[0]; } return $tables; } ?> <form> Column <input type="text" name="column"> <input type="submit" name="sub" value="Find"> </form> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 ok, here's the latest script, and I got a parse error: <?php // Check if the column in the database is in 1 table or another function what_table($column) { // Your two queries... $first = "SHOW COLUMNS FROM `cf_users`"; $second = "SHOW COLUMNS FROM `cf_users2`"; // Start query one $result = mysql_query($first); // Debug... if(!$result){ die('There was an error.'); } // Start loop while($row = mysql_fetch_assoc($result)) { if($row[$column] == $column) { $table = "cf_users" } // this is line 40 else { $table = "cf_users2" } } return $table; }; ?> Parse error: syntax error, unexpected '}' in /home/ace/public_html/conflictingforces/functions.php on Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 1, 2007 Share Posted December 1, 2007 C'mon bro... you're good enough at PHP to fix a parse error... = / if($row[$column] == $column) { $table = "cf_users"; } And I tell you again, better formatting on your part will make finding rogue or missing delimiters much easier. PhREEEk Quote Link to comment Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 same problem with the "else" bit too Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 how in hell did I miss that :-\ Thanks guys. EDIT: Well the function is working now, except it works for every page except for the one I intended it for :-\ I'm back to the Error "cf_users.supplydrop column doesnt exist" again. Is their a way to make it so I can make a if statement, and if the person is on a certain page, It will change what is in $table name? The only problem I can see with this is. My pages are all include_once() in my index.php page, so my url's are like: index.php?page=ability And I don't thinking the GLobal Variables can pick up the ? and beyond. any ideas? Quote Link to comment Share on other sites More sharing options...
wsantos Posted December 1, 2007 Share Posted December 1, 2007 Topic Closed ? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 1, 2007 Author Share Posted December 1, 2007 not quite... I'm back to the Error "cf_users.supplydrop column doesnt exist" again. Is their a way to make it so I can make a if statement, and if the person is on a certain page, It will change what is in $table name? The only problem I can see with this is. My pages are all include_once() in my index.php page, so my url's are like: index.php?page=ability And I don't thinking the GLobal Variables can pick up the ? and beyond. any ideas? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 bump Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 anyone??? Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 2, 2007 Share Posted December 2, 2007 The only problem I can see with this is. My pages are all include_once() in my index.php page, so my url's are like: index.php?page=ability And I don't thinking the GLobal Variables can pick up the ? and beyond. any ideas? I don't exactly understand you but code like this will pick the page name and all passed value after ? too. <?php $QueryString=""; foreach ($_GET as $key => $value) { $value = urlencode(stripslashes($value)); if($QueryString!="") $QueryString .="&"; $QueryString .= "$key=$value"; } $pageName=basename($_SERVER['PHP_SELF'] ); $page =$pageName."?".$QueryString; echo $page; // will show the full page echo $QueryString; // will show after ? ?> Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 Awesome, Thanks Quote Link to comment Share on other sites More sharing options...
monkeybidz Posted December 2, 2007 Share Posted December 2, 2007 Is this topic solved, or can you use a Session User or header Location to define the page=ability? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 I think were good, but this page finding way is the quick fix, gonna do some more trial and testing on the way it should be done, with my function. Thanks all. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.