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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度