dongzhou4727 2012-01-08 03:01
浏览 65
已采纳

如何从基于数组的mysql列获取值数组

I'm new to PHP and as I'm getting into arrays its throwing me for a loop. No pun intended. Everything below is giving me what I need so far. $datum contains an array of submission ID's I need. What I'd like to do next is query a table to match all of my submission ID's in $datum to an Image ID column and put that result into an array containing all of the image ID's. Then I need to query the image table to get the file name for each of the Image ID's and put it into a SELECT box. Im just not sure how to work the loops with the arrays. I just can't make FOR EACH and WHILE do what I need. Ive put what Id like to do in plain english below the code. Thanks for any help.

<?php
$mask5 = $_GET["var1"];
require("codebase/grid_connector.php");
$res = mysql_connect("", "", "");
mysql_select_db("supplydb");
//Get Category ID
$cat    = mysql_query("SELECT category FROM submissions WHERE submissions.submission_id='$mask5'");
$rows   = mysql_fetch_array($cat, MYSQL_ASSOC);
$array  = $rows['category'];
//Get Manufactuer ID
$man    = mysql_query("SELECT manufacturer_id FROM submissions WHERE submissions.submission_id='$mask5'");
$arows  = mysql_fetch_array($man, MYSQL_ASSOC);
$array1 = $arows['manufacturer_id'];
//Get All Submission ID's for this popup
$datum  = array();
$result = mysql_query("SELECT submission_id FROM submissions WHERE submissions.category='$array' AND submissions.manufacturer_id='$array1'");
while ($rowd = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $datum[] = $rowd;
} 

////// WHAT ID LIKE TO DO.......

mysql_query("SELECT image_id FROM imagsub WHERE image_id = $datum[]...

$answers = new array from above result

THEN

mysql_query("SELECT filename FROM images WHERE image_id = $answers[]

THEN

Put into a select box.

Some of this I can struggle with and try to figure out but right now I can't seem to get an array of values from one column in a table based on another array. Any help with the rest is just gravy. Thanks in advance.

  • 写回答

2条回答 默认 最新

  • douao1858 2012-01-08 03:13
    关注

    It might be simpler if you create a query that joins all the data between your tables instead doing on PHP side. It's hard to understand your database and tables relationships, but definitely do it on SQL side, and don't query the database each time for each table you want to join.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据