chocopi Posted May 29, 2007 Share Posted May 29, 2007 Ok so in my database i have information like w_2 and i_1. The letter is reference to another table name which I need to use an array for and the number is refernce to an id. So what I need is for when I get the data for it to be split into the letter and the number separately and then put the letter into an array to get the table name. This is what I have put together to show you what I mean: <?php $id = 1; // Made up just for this $query = "SELECT column FROM tablename WHERE id='$id'"; $row = @mysql_fetch_assoc($query) or die("Invalid query, please contact an administrator!"); $result = $row['column']; // Need to split up result $letter = ''; $number = ''; // With the letter $array = array('','table1','table2','table3'); $array = $array[$letter]; $query = "SELECT column FROM $array WHERE id='$number'"; ?> Thanks, ~ Chocopi Quote Link to comment https://forums.phpfreaks.com/topic/53423-gettting-data-from-database-the-splitting-up-then-using-an-array/ Share on other sites More sharing options...
per1os Posted May 29, 2007 Share Posted May 29, 2007 <?php $id = 1; // Made up just for this $query = "SELECT column FROM tablename WHERE id='$id'"; $row = @mysql_fetch_assoc($query) or die("Invalid query, please contact an administrator!"); $result = $row['column']; // Need to split up result list($letter, $number) = split("_", $row['column']); // With the letter $array = array('','table1','table2','table3'); $array = $array[$letter]; $query = "SELECT column FROM $array WHERE id='$number'"; ?> www.php.net/list www.php.net/split note untested. Quote Link to comment https://forums.phpfreaks.com/topic/53423-gettting-data-from-database-the-splitting-up-then-using-an-array/#findComment-264008 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.