Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.