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 Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/ 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 Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403477 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> Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403504 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 Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403829 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 Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403841 Share on other sites More sharing options...
Barand Posted December 1, 2007 Share Posted December 1, 2007 same problem with the "else" bit too Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403843 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? Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403852 Share on other sites More sharing options...
wsantos Posted December 1, 2007 Share Posted December 1, 2007 Topic Closed ? Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403855 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? Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403881 Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 bump Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-403905 Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 anyone??? Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-404066 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 ? ?> Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-404071 Share on other sites More sharing options...
MasterACE14 Posted December 2, 2007 Author Share Posted December 2, 2007 Awesome, Thanks Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-404110 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? Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-404123 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. Link to comment https://forums.phpfreaks.com/topic/79665-solved-mysql-checking-if-a-column-is-in-table-1-or-table-2/#findComment-404138 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.