Jump to content
php.lv forumi

attela nolasīšana no foldera


tehnic

Recommended Posts

Ilgu laiku štukoju kā īsti panākt rezultātu bet man, kaut kas nesanāk.

$dir = @ opendir("include/maps/");
while (($file = readdir($dir)) !== false)
$map = mysql_query("SELECT * FROM `dmor`") or die(mysql_error());
while ($row = mysql_fetch_array($map))  {
 if ($file == $row['curmap']){
 echo "<a href=\"include/dmmoni/index.php?width=275\" class=\"jTip\" id=\"divi\" name=\"Karte 1\"><img class=\"withmargin\" src=\"include/maps/" .$row['curmap']. ".gif\"></a>"; 
 }
 else {
 echo "<a href=\"include/dmmoni/index.php?width=275\" class=\"jTip\" id=\"divi\" name=\"Karte 2\"><img class=\"withmargin\" src=\"include/maps/na.gif\"></a>";
 }
 };
closedir($dir);

Tā kā php vēl tikai mācos, tad štellēju kopā kā māku.

Būtība tāda, vajad lai no db atlasa info par kādu karti mest virsū, pēc tam ar opendir atrod šo karti mapē, un attēlo viņu, ja šādas kartes nav, tad izmet na.gif vai vienalga ko.

Bet - ja tāda karte ir - viņš padod pareizi, ja nav viņš no db nolasa un nesalīdzina kuru if vai else ir jāizpilda!

Ceru ka skaidri izteicos!

 

Piemēram:

Folderī ir

karte1

karte2

karte3

db padod ka tagad jaattēlo karte 1

if ($file == $row['curmap']){

ir ok izpildām -

db padod ka tagad jaattēlo karte 5

if ($file == $row['curmap']){

katre nav - bet vienalga viņš padod

Edited by tehnic
Link to comment
Share on other sites

Es taisītu šādi:

$map = mysql_query("SELECT * FROM `dmor`") or die(mysql_error());
while ($row = mysql_fetch_array($map))  {
if(is_file('./include/maps/' . $row['curmap'] . '.gif')){
echo "<a href=\"include/dmmoni/index.php?width=275\" class=\"jTip\" id=\"divi\" name=\"Karte 1\"><img class=\"withmargin\" src=\"include/maps/" .$row['curmap']. ".gif\"></a>"; 
 }
 else {
 echo "<a href=\"include/dmmoni/index.php?width=275\" class=\"jTip\" id=\"divi\" name=\"Karte 2\"><img class=\"withmargin\" src=\"include/maps/na.gif\"></a>";
 }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...