2011-12-15 5 views
1

id가 f1, f2, f3, ..., f20 인 열이있는 mysql 테이블이 있습니다. 여기서 id는 productID와 f1, ... f20입니다. 제품 기능입니다. 각 제품에 따라 일부는 모든 항목을 갖거나 일부만 채워질 수 있습니다.php & mysql - 단일 행의 열을 반복하고 배열에 값을 전달합니다.

각 열은 A, B, C, D를 다른 언어의 값 (= 프랑스어 A = 영어, B 등)

는 I가 선택해야되는 # B를 # C를 # 1 (D)와 같이 구분 된 문자열을 보유 각 행의 값 (f1, f2 ...)을 '#'으로 분해하여 필요한 언어 부분을 얻은 다음 배열을 통해 값을 제품 사양 페이지에 사용하십시오.

$ ls = ('green', 'M', '100', ' 아이들 ...) 등? 추신 : 나는 알고있다, 복잡하다. 그러나 나는 더 좋은 생각을 지금 생각해 낼 수 없다.

+0

일부 코드가 표시 될 수 있습니까? – Toto

+0

전체 테이블 행 예제를 하나만 줄 수 있습니까? – noob

+0

내가 가지고있는 모든 것은 나의 mysql 테이블과 종이에 많은 스케치이다. – bikey77

답변

4

이 시도 :

$result = mysql_query("..."); 

while ($row = mysql_fetch_array($result, MYSQL_NUM)) { 
    $arr = array(); 
    foreach ($row as $k=>$v) 
    { 
     $features = explode("#", $v); 
     $value = $features[1]; // get the specific language feature 
     $arr[] = $value; 
    } 
    $specs = join(", " , $arr); 
} 
+1

이 작업은 바로 진행되었습니다. 감사합니다! 나는 조인 기능에 대해 몰랐다. – bikey77

+0

Hello @swatkins ...이 문제를 해결하는 데 도움을 주시겠습니까? http://stackoverflow.com/questions/28493201/how-to-find-the-total-distance-traveled-based-on-geo-points-stored 동일한 문제와 관련된 데이터베이스 – Prabs

0

이 확실하지 않음이 가장 좋은 방법의 토고하지만 당신은 그 방법은 랭

<?php 
$langs=array('eng'=>0,'fr'=>1,'ger'=>2,'geek'=>3); 


while ($row=mysql_fetch_assoc($result)) { 
    $specs=explode('#',$row['f1']); 
    $other=explode('#',$row['f2']); 
    ... 
} 
//Get lang from cookie that you could set elsewhere 
$lang=(isset($_COOKIE['lang']))?$_COOKIE['lang']:'eng'; 

echo $specs[$langs[$lang]]; 

?> 
0

내 솔루션을 결과에 액세스하여 랭 가문과 배열을 정의 할 수 있습니다 I 질문을 이해 :

// Make a MySQL Connection 

$sQuery = "SELECT f1,f2,... FROM table WHERE id = ..."; 

$oResult = mysql_query($sQuery) or die(mysql_error()); 

//Fetch assoc to use the column names. 
$aRow = mysql_fetch_assoc($oResult); 

//Prepare the product properties array 
$aProductProperties = array("English"=>array(),"French"=>array(),"Dutch"=>array()); 

//Loop over all the columns in the row 
foreach($aRow as $sColName=>$sColVal){ 
//Explde the column value 
    $aExplodedCol = explode("#",$sColVal); 
    //The code below could be nicer when turned into a looped that looped over every language, 
    //But that would make the code less readable 
    $aProductProperties['English'][$sColName] = $aExplodedCol[0]; 
    $aProductProperties['French'][$sColName] = $aExplodedCol[1]; 
    $aProductProperties['Dutch'][$sColName] = $aExplodedCol[2]; 

} 

//Done, you should now have an array with all the product properties in every language 
관련 문제