Jump to content

Gettting data from database the splitting up then using an array


chocopi

Recommended Posts

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.