Forum Moderators: coopster
$data[] --Array with multiple contents
$sql_2 = "SELECT intsch_id FROM interest_scholarships_interest WHERE interests=$character";
$result_2 = mysql_query($sql_2);
$data_2 = array();
foreach ($data as $character)
{
while ($row_2 = mysql_fetch_array($result_2))
{
$data_2[] = $row_2;
}
}
Thanks,
Travis
$data = range(0,12); // creates a 0-12 array, otherwise $data should be an array!
$data2 = array();
$data_new = array();
$generic_query = "SELECT intsch_id FROM interest_scholarships_interest WHERE interests=";
foreach ($data as $k => $character)
{
$query = $generic_query."'".$character."'";
$i = 0;
while ($r = mysql_fetch_array($query))
{
$data2[$i++] = $r['intsch_id']; // or $r['0']
}
// now add the data2 array into the data array
$data_new[$k] = $data2;
// delete data2
unset($data2);
}
Array ( [0] => Array ( ) [1] => [2] => [3] => [4] => [5] => )
It doesn't have the values that I was hoping it would...
Also here is the updated script segment:
$data // array that has values
$data_2 = array();
$data_new = array();
$generic_query = "SELECT intsch_id FROM interest_scholarships_interest WHERE interests=";
foreach ($data as $k => $character)
{
$query_3 = mysql_query($generic_query."'".$character."'") or die(mysql_error());
$i = 0;
while ($r = mysql_fetch_array($query_3))
{
$data_2[$i++] = $r['intsch_id'];
}
$data_new[$k] = $data_2;
unset($data_2);
}
print_r($data_new);
$data; // array that has values
$data_new = array(array());
$generic_query = "SELECT intsch_id FROM interest_scholarships_interest WHERE interests=";
foreach ($data as $k => $character)
{
$query_3 = mysql_query($generic_query."'".$character."'") or die(mysql_error());
while($r = mysql_fetch_array($query_3)){
$data_new[$k][] = $r['intsch_id'];
}
}
echo '<pre>';
print_r($data_new);
echo '</pre>';
My suggestion to you is to make sure that you are actually receiving results from your queries.
Hope this helps. Good luck!
anyways, why are u using multiple queries and not just 1?
SELECT intsch_id FROM interest_scholarships_interest WHERE interests IN ('bla', 'di', 'bla')
or
SELECT intsch_id FROM interest_scholarships_interest WHERE interests='bla' OR interests='di' OR interests='bla'
seems a whole lot easier to me
If that's true, I can give you my coding based on it, therefore you can change it if needed:
$data2 = array();
foreach ($data as $k => $drow)
{
$sql = "SELECT intsch_id FROM interest_scholarships_interest WHERE interests='" . $drow['interests'] . "'";
$result = mysql_query($sql);while ($row = mysql_fetch_array($result))
{
$data2[$k][] = $row;
}
}
In array terms, is it something like this:
Array (
something => array (0, 1, 3, 4, n)
something2 => array(n, n+1, n+n)
etc...
)
Yeah?
Now, tell us what the values of '$data' is. Are they keyed? What's the relation with the values in the DB?
TABLE_A
COLUMN_A ¦ COLUMN_B
A ¦ 1
A ¦ 2
A ¦ 3
A ¦ 4
B ¦ 1
B ¦ 3
B ¦ 4
C ¦ 2
C ¦ 3
C ¦ 4
This is where my last post was concerned in terms of wanting to dynamically get an array of column_b's field values that corresponded with a specific A values... The A values were stored as SESSION variables too... So it is specific to each person that logs in. Then, here is the second part.
TABLE_B
COLUMN_A ¦ COLUMN_B
0001 ¦ 1
0001 ¦ 2
0001 ¦ 3
0002 ¦ 1
0002 ¦ 3
0003 ¦ 2
0004 ¦ 3
0004 ¦ 4
Column_b references the same data in Table A as in Table B. Column A references a different table. Now, from the fields I received from column_b in table_a, I want to now pull the values from column_a in table_b. Also, is there a problem if multiple values from the array we received from table_a reference the same field in column_a (example: 1 & 2 in column_b reference 0001)? All right, and that's not everything... I then want to display a table full of information that has a primary key of table_b column_a's data and those results in tabular format with a master_detail_page setup... So, yes, I have quite an undertaking on my behalf. I haven't been coding that long and all of the references I've used barely ever talk about dynamic data to the extent that I want to use it... Does anyone have any ideas on what I can do in terms of research? I hate to be bothersome and ask all of you to do the coding for me, and that's why I'm trying to figure out steps on my own, but when I try to figure it out on my own and something doesn't work like I thought it would, boy is it frustrating! So, that's where I am... Anyone have ideas?
Travis
P.S. Should I just get a professional programmer?
Does anyone have any ideas on what I can do in terms of research?
I hate to be bothersome and ask all of you to do the coding for me.
Should I just get a professional programmer?
Anyway, if you have any more questions regarding how you should go about this then don't hesitate to reply to this post.
Good luck!
Thanks, and I'll be posting regularly.
Travis