PHP Languages and database -


is long question hope can me

well have added system switch language on site want make language file dynamyc...

i try explain so:

i have file create slide on home page:

<?php  $sql = "select img_url, caption  cc_homeslide  order position asc"; $result = mysqli_query($conn, $sql);  if (mysqli_num_rows($result) > 0) {     // output data of each row     while($row = mysqli_fetch_assoc($result)) {         echo "<div><figure><div class='dark-effect'><img class='lazyowl' data-src='images/slide_home/fake_img.png' alt='awesone food' style='background-image: url(images/slide_home/". $row["img_url"]. ")' /></div><figcaption>". $row["caption"] ."</figcaption></figure></div>";     } } else {     echo "0 results"; }  ?> 

perfect working. want switch $row["caption"] $lang["slide_caption"]

why? because in file en.php have this:

<?php /* ------------------ language: english ------------------ */  $lang = array();   //head  $lang['page_title'] = 'food delivery quality restaurants in hong kong'; $lang['page_description'] = 'order food favorite restaurant , delivers them home or office ● pay online or cash on delivery'; $lang['page_keywords'] = 'order food online, food delivery in hong kong, quality restaurants delivery';  // menu  $lang['lang'] = 'eng'; $lang['loc_hk'] = 'hong kong'; $lang['loc_kw'] = 'kowloon';  //slide require_once ("connect.php");  $sql = "select img_url, caption  cc_homeslide  order position asc"; $result = mysqli_query($conn, $sql);  if (mysqli_num_rows($result) > 0) {     // output data of each row     while($row = mysqli_fetch_assoc($result)) {         $lang['slide_caption'] = $row["caption"];     } }  ?> 

but problem can not make caption match right row on database. code getting same caption rows on database...

so need make $lang['slide_caption'] = "caption on each row"

any idea?

i have tried explain in best way if interested , can not understand let me know , going explain again

each key in array must unique. loop generating $lang['slide_caption'] = $row["caption"]; returning each row value same variable - $lang['slide_caption'] ever last value loop.

build $slidecaptions array hold captions, using unique field database table key:

$slidecaptions = array();  while($row = mysqli_fetch_assoc($result)) {     $slidecaptions[$row["id"]] = $row["caption"]; } 

then, access caption in array using key output value:

while($row = mysqli_fetch_assoc($result)) {     echo "<div>...</div>           <figcaption>". $slidecaptions[$row["id"]] ."</figcaption></div>"; } 

Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -