PHP - Trying To Change Inline Image Conditionally In An Array...help
Currently, I insert a small thumbnail image at the begging of each row in a set of records from a mysql query. But that image is the same image for each record in that array.
Is there a way to conditionally change which image is used, based on a value either in that same table, or a related table. See attached screenshot... and here's my current code.... Code: [Select] <?php $query = "select address from nvc"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $details=''; $details.='<li class="menu"><a href=detail.php?address='.(urlencode($row['address'])).'><img src="thumbs/house.png" /><span class="name">'.$row['city'].'</a>'; $details.='</li>'; echo($details); } ?> Thank you for any input. Similar TutorialsAlright, I looked though the read me's, went over the FAQ's... Think it is time to post...
So, this lump is what I got from going though google and piecing together the bits that looked good.
<?php $db_host = "****"; $db_user = "****"; $db_pwd = "****"; $database = "****"; $table = "****"; $query = "SELECT * FROM {$table}"; $conn = mysqli_connect($db_host, $db_user, $db_pwd, $database); $result = mysqli_query($conn,$query) or trigger_error($query . ' - has encountered an error at:<br />' . mysqli_error($conn)); $fields = mysqli_fetch_fields($conn); $field_count = mysqli_num_fields($conn); echo '<table border="1" style="width:100%">' . "\n" . '<tr>'; $i = 0; foreach($fields as $field) { if(++$i == 1) { echo '<th colspan="' . $field_count . '">' . $field->table . '</th></tr><tr>'; } echo "\n" . '<th>' . $field->name . '</th>'; } echo '</tr>'; while($row = mysqli_fetch_row($result)) { echo '<tr><td>' . implode('</td><td>' , $row) . '</td></tr>'; } echo '</table>'; ?>The goal is to display the table and conditionally format the contents. Let's forget about the conditional part (thinking if/than but don't know how I'm going to do that yet) and focus on the key problem: displaying the table. I have tested this code. It works...to a point. it displays the table and its contents but no headers. I know my issue is in line 20 and 22 but I can not for the life of me figure it out. If it is stupidly easy (for you) please remember that I am not a coder. At best I am a scripter when it comes to linux. I am over my head on this stuff. Thank you all for any help you can give me Edited by TheAlmightyOS, 18 November 2014 - 03:30 PM. Can someone tell me why this code will not work? It's supposed to update the quantity in a shopping cart by taking the user input and changing the value of the array. I can add items by clicking the 'add to cart' button, but as you know that only works one at a time. Once you make a selection you have the opportunity to go to the cart and modify the quantity by entering in a numeric value; so instead of clicking 10 times you can just type 1, 0 to get to 10. Is there any other info I can provide to convey what I'm trying to do? I'm new to php so I don't know why it's not working, this looks right according to php.net but something is wrong. if(isset($_POST['submit'])) { foreach($_POST['quantity'] as $key => $value) { if($value==0) { unset($_SESSION['cart'][$key]); }else{ $_SESSION['cart']['$key']['quantity']=$value; } } } errors below: Invalid argument supplied for foreach() illegal string offset 'cart' Edited by somerandom, 22 October 2014 - 06:04 PM. Good Evening, I'm having no luck in something that I'm sure is incredibly simply... If I have an array like the following... Code: [Select] $array = array(15,22,0,43,0,6);How can I find and replace all the zeros with a one? Regards, Ace I need some help converting my captured array values into keys and later add arrays as the values. This might help explain what I'm looking for: I currently have Code: [Select] Array ( [0] => Meat [1] => Veg ) But I'm after Code: [Select] Array ( Meat => Veg => ) My end result will be: Code: [Select] [Veg] => Array ( [Potatoe] => 12 [Cabbage] => 24 [Cucumber] => 56 ) [Meat] => Array ( [Chicken] => 23 [Beef] => 90 ) I think either array_values() may help but I'm not too sure how to use it. Hi
I'm totally green when it comes to php, but am learning it the hard way. Any help is appreciated.
I have a form the currenty uses a custom taxonomy but it has a text field, and I want it to call and list the taxonomy items with checkboxes so instead of entering words the visitor can just multiple check off the taxonomies that relate to them.
It's a job board, this is the job skill part that relates to their expertise.
There is a job category in the form, and I tried to use the syntax to get the taxonomy and implode it but
I really don't know what I'm doing.
See the "skills" item? I want to make that a bunch of checkboxes to allow selection the the pre defined resume_skills taxonomy.
http://outsourcing.j...it-resume-free/
Any help would be great, and I'm not sure what code I need to put in here.
Mark
I've figured out how to change all of an arrays keys to lowercase: $lower_case_array = array_change_key_case($mixed_array, CASE_LOWER); But I can't seem to find a way to change the values of an array to lower case. Is there a simple way to do this? I am echoing a variable that is an array. I want to change the first part of the variable but don't know how to manipulte names inside the ['brackets'] Code: [Select] echo $row['v1_name']);?> lets say I have a value called $var = v1. How do I substitute that like this: Code: [Select] echo $row[$var.'_name']);?> I know the above doesnt work, but thats what i want it to do :-) Hello, I'm a new building my career as a web developer/designer and i'm attempting to create an array that holds different attributes of all the web projects. Site1 => array('www.siteurl.com','hostAccountName','Offline domain name',) , Site2 => array('www.site2url.com','hostAccoun2tName','Offline domain2 name') , Site3 => array('www.site2url.com','hostAccount3Name','Offline domain3 name') , I have many sites in the multidimensional array BUT each has the same format of attributes. I store this entire array in one file that gets included, and based on some logic later , the script will decide which site i'm currently working on and thus that site's attributes must be used, since i will just use one variable where these attributes are needed and leave it upto some logic to decide which site's attributes to use. Objective of the code : To change the array keys of each site's attributes from 0,1,2 etc to more readable strings for later use to directly access values. I'm creating an array with the values first and then running some code to change the keys later because i might decide to change the key names later and i can't manually edit it for each of the array values because the array might grow much larger. Site1 => array ([0] => 'www.siteurl.com', [1] => 'username@hostserver', [2] => 'siteOfflineDomain'); must change into Site1 => array (['siteUrl] => 'www.siteurl.com', ['hostingUserName'] => 'username@hostserver', ['OfflineVirtualHost'] => 'siteOfflineDomain'); And this must happen in a foreach loop and go through all the sites to change all the default 0,1,2 indices, to the index names i provide. Code : $siteList = array ( 'site1' => array ( 'www.site1.com', 'site1@host', 'site1_offline' ), 'site2' => array ( 'www.site2.com', 'site2@host', 'site2_offline' ), 'site3' => array ( 'www.site3.com', 'site3@host', 'uttarkar_offline' ) ); foreach ($siteList as $sitePrefix => $siteAttributes) { foreach ($siteAttributes as $oldIndex => $attribute) { switch ($oldIndex) { case 0 : $siteAttributes['siteUrl'] = $siteAttributes[$oldIndex]; unset($siteAttributes[$oldIndex]); break; case 1 : $siteAttributes['hostserverUserName'] = $siteAttributes[$oldIndex]; unset($siteAttributes[$oldIndex]); break; case 2 : $siteAttributes['offlineDomainName'] = $siteAttributes[$oldIndex]; unset($siteAttributes[$oldIndex]); break; } } echo 'The newly edited attributes array for ',$sitePrefix,'is '.print_r($siteAttributes),'<br><br>'; } Problem : This script works great, and the indices for the attributes get changed as expected, as you will see in the echo statement. But if i do a echo $siteList['site1']['siteUrl'] after the code, it says 'unknown index siteUrl'. Then i check the entire array with print_r($siteList) , and all the index keys are back to being 0,1,2!. My guess is that theres something i'm missing here to make them stick, but i spent 3 hours trying to figure it out, and i was getting a bit impatient, so can i get some help on this one please , thanks. Using php I have a dynamically filled select box with the names of images. How can I get an image box on my page and change upon selection? Hi all, I am dealing with an html page in which a dynamically created PNG image is shown with: <img src="createchart.php"> The problem arises when users try to download the image since the default name that appears is just "createchart.php". Is there any way to make the browser suggest something like "chart.png"? Than you guys for your help, Mam This creates an image 1500x1500 pixels. But it creates it in black... how can i make it white. And i have to use imagecreatetruecolor() not imagecreate(). <?php $im = imagecreatetruecolor(1500,1500); // Output the image to the browser header('Content-type: image/jpg'); imagejpeg($im); imagedestroy($im); ?> Thanks! Main URL of website home page: www.mysite.com and this shows image "A" in the header. I want to have a marketing campaign which will send people to my site via this link: www.mysite.com/index.php?ref=att When people get to my site via the 2nd link, I want to show image "B" instead of image "A". I put this at top of home page... Code: [Select] require_once("includes/session.php"); if (isset($_GET['ref']) && ($_GET['ref'] == "att")) { $_SESSION['ref'] = "att"; } else { } and this code is in my header include file, a little further down on the page... Code: [Select] <?php if (isset($_SESSION['ref']) && $_SESSION['ref'] == "att") { echo "<span class='phone'><img src='/images/B.png' /></span>"; } else { echo "<span class='phone'><img src='/images/A.png' /></span>"; } ?> Does this look right? because I can't get it to work. It's showing image A regardless of which URL I use. I have to be missing something obvious because I really thought this would be super easy to do. If anyone sees any problems, let me know. But I'll keep testing and hopefully find my mistake. Thanks! Hi,
I want to show one image for the new visitors of my website and another for the returning visitors. What I want to do is that after the visitor reload the page he will see another image instead of the first one.
HI I'm thinking to do something like this , I've seen this in a website ,I'm a php designer but i don't know who something like this can be done . it's a website that sells sofas . we've the ability to change the color and fabric and see the result right away . for example ,this is the default sofa : then I can select a part of it and I can choose the fabric and color , then it make the result : thats it , How can I do that ? What should I do ? I'm really looking to hear from you King Regards i am new to web designing,
i don't know much about javascript.
<select id="plan" align="center" valign="center"> I have a PHP script that uploads images to a folder on my server (attachments folder). Currently the folder sits within my webroot and is publicly accessible (I have to use chmod 777 due to permissions issue). So, I created the "attachments" folder outside of my webroot (so that it is not publicly accessible), but I do not know how to set the path in the PHP code to upload it to that "attachments" folder outside of the webroot. As you see in the snippet of PHP code below, the code currently uploads the the "attachments" folder within the www (webroot) directory. How do I make it upload to the "attachments" folder OUTSIDE of the www (webroot) directory? foreach($files[$form] as $file){ $str = $file[1]; if (eval("if($str){return true;}")) { $_values[$file[0]] = $_FILES[$file[0]]["name"]; $dirs = explode("/","attachments//"); $cur_dir ="."; foreach($dirs as $dir){ $cur_dir = $cur_dir."/".$dir; if (!@opendir($cur_dir)) { mkdir($cur_dir, 0777);}} $_values[$file[0]."_real-name"] = "attachments/".date("YmdHis")."_".$_FILES[$file[0]]["name"]."_secure"; copy($_FILES[$file[0]]["tmp_name"],$_values[$file[0]."_real-name"]); @unlink($_FILES[$file[0]]["tmp_name"]); }else{ $flag=true; if ($_isdisplay) { //$ExtFltr = $file[2]; //$FileSize = $file[4]; if (!eval("if($file[2]){return true;}")){echo $file[3];} if (!eval("if($file[4]){return true;}")){echo $file[5];} $_ErrorList[] = $file[0]; } } } Hey guys! I have the following php code that grabs variables (and the browsed image) from Flash. //FLASH VARIABLES $Name = $_POST['Name']; $itemNumber = $_POST['itemNumber']; $filename = $_FILES['Filedata']['name']; $filetmpname = $_FILES['Filedata']['tmp_name']; $fileType = $_FILES["Filedata"]["type"]; $fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000); list($filename, $extension) = explode('.', basename($_FILES['Filedata']['name'])); $filename = $Name; $target = $filename . $itemNumber . "." . $extension; // Place file on server, into the images folder move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$target); This works perfect, but what I want to change is the width and height of the uploaded image. Any ideas/suggestions on how this could be done? Thanks in advance!! Cheers! This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=347058.0 Hi, I have a game image gallery using arrays to hold the current images, and when you go to a new location, like "newLocation=2" , it goes to a new array of background images. The problem is, when I try it in my browser, and I put in a new array of image for like, "location 2", The image doesn't show up, the images from location 1 show up. This is driving me nuts because I want to start adding content to the zones of my game already.LOL!. If anyone can help please I'd be very grateful. Thank you. Derek ok, here is the code to the page, I only included the parts of the page that are relevant to what I am talking about. Code: [Select] <?php session_start(); //$currentBackground=''; $echoLocation=''; $player=''; $monsters=''; $_SESSION['player'] = $player;// set this right after they log in, run this once, eventually in database. $_SESSION['monsters']=$monsters; $currentMonsterLevel='';//get rid of this eventually and put in session variable cuz we use it on other pages. $currentPlayerLevel=''; $error=''; $playerHp='';//get rid and make session var. $monsterHp=''; $echoPlayerMana=''; $echoMonster=''; $echoSpell=''; $player=''; $monsters=''; $playerMessage=''; $monsterMessage=''; $currentPLayerLevel =''; } } ////////////////////////////////////////////////////////////////////////////////// /////////////////////////////GAME NAVIGATION AND MONSTER SEARCH CODE NOT FINISHED////////////////////////////////// $locations[0] = array(); $locations[1] = array( 'background_images' => array( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME3.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME4.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME5.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>", "<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png '/>", "<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/teardrop_ocean_protector/teardrop_ocean_protector.png'/>" ) ); $locations[2] = array( 'backgroundImages' => array( "<img src='sundragon_environments/shore/teardrop_shore/teardrop_shore.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>" ) ); if(isset($_GET['newLocation'])) { $_SESSION['current_location']=$_GET['newLocation']; } if(!isset($_SESSION['current_location']) && !isset($_SESSION['current_background']) && !isset($_SESSION['currentMonster'])) { $_SESSION['current_location'] = 0; $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if($_SESSION['current_location'] != 0) { if(!isset($_SESSION['current_background']) && !isset($_SESSION['current_monster'])) { $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if(isset($_GET['further'])) { //below is- inside the locations array, teardrop ocean (1) the background image is 4(example)+1 is set, then //do this if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']+1])) { $_SESSION['current_background']+=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']+1])) { $_SESSION['current_monster']+=1; } } elseif(isset($_GET['back'])) { if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']-1])) { $_SESSION['current_background']-=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']-1])) { $_SESSION['current_monster']-=1; } } $currentBackground=$_SESSION['background'][$_SESSION['current_background']]; $currentMonster=$_SESSION['monster'][$_SESSION['current_monster']]; } else { //?newLocation=1 means set it to Teardrop ocean. $currentBackground = ' <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="5,176,81,249" href="?newLocation=1"/> </map>'; $currentMonster = ''; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Realm of the Sun Dragon</title> <link rel="stylesheet" type="text/css" href="css/gamestyles.css"> <style type="text/css"> body { margin-top:-32px; padding:0; color: gold; } table { color: black; } .style8 {color: #000000} </style> </head> <body oncontextmenu="return false;"> <div id="container"> <div id="monster_message"> <?php echo "this is the monster battle and NPC talk window";?> </div> <div id="currentWeapon"> <img src="sundragon_interface_template/items/swords/sword_shrunk.png" width="190" height="65" /> </div> <div id="iframe_player_top_lft" > <div id="left_player_stats"><table align="center" width="30" border="0"> <tr> <td><strong>HP</strong></td> <td><strong><font color="red"><?php echo $playerHp;?></font></strong></td> </tr> <tr> <td><strong>MANA</strong></td> <td><strong><font color="green"><?php echo $echoPlayerMana;?></font></td> </tr> <tr> <td><strong>EXP</strong></td> <td><strong><font color="blue">999</font></strong></td> </tr> <tr> <td><strong>PLAT</strong></td> <td><strong><font color="white">999</font></strong></td> </tr> </table></div> <p> </p> <p> </p> <p> </p> <p align="center"><strong><br /> <span class="style8">Octalisk (Level <?php echo $currentMonsterLevel;?>) </span></strong> <br/> <strong><span class="style8">HP</span><font color="red"> <?php echo $monsterHp;?></font></strong> </p> <div id="spelleffectsleft" > <div class="divcenter"> <div align="center"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <!--end divcenter--> </div><!--end spell effects--> <div id="bottomspellsleft" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> <!--end div center--> </div><!--end bottomspells--> </div><!-- end player div--> <div id="iframe_spell_foreground"><?php echo $echoSpell;?></div> <div id="iframe_monster_background"><?php echo $currentBackground;?></div> <div id="iframe_transparent_monster"><?php echo $currentMonster;?></div> <!--not here--> <div id="iframe_player_top_right" > <table width="160" height="64" border="0" align= "center"> <tr> <td width="160"><div align="center"> <p><strong><br /> Silverglade (Level: <?php echo $currentPLayerLevel;?>)<br /> </strong></p> </div></td> </tr> </table> <div class="spelleffects" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <div class="bottomspells" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> </div> <div id="iframe_chat_right"> the data from the chat message box will be output to this div</div> <!--not here--> <div id="iframe_player_center_bottom" align="center" ><div style="display: inline;"> <form style="display: inline; margin: 0;" ...> <form style="display: inline; margin: 0;" action='gamestart_NEWEST.php' method='post'><input type='submit' name='attack' value='Attack'/><input type="submit" name="search" value="search" /><input type="submit" value="cast spell" name="spell" /><input type="submit" name="inventory" value="Inventory"/></form> <form style="display: inline; margin: 0;" method="get" action=""><input type="submit" value="go further" name="further" /> <input type="submit"value="Go back" name="back"/></form> </form> </div> <div id="chat"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Message:</strong> <textarea name="message"></textarea> <input type="submit" name="submit" value="Chat"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div></div></div> <!--not here--> <div id="log_off"> <a href="logout.php"><strong>LOG OFF</strong></a> </div> <!--not here--> </div> </body> </html> I asked a question in another thread about making this script work in multiple instances but now I can't even get it to work! Code: [Select] <?php $cpics = array ( "images/sidebar/party1.jpg", "images/sidebar/party2.jpg", "images/sidebar/party3.jpg" ); $index = rand(0, 2); $cbanner = $cpics[$index]; ?> And in the http://do-rightweb.com/1-test.php test page Code: [Select] <img src="$cbanner"> Thanks very much for your help. |