PHP - Thresholding An Image Producing Strange Values At Output.
I am trying to produce a thresholded image with only an rgb value of zero or 255.
As you can see, although I only output 0 and 255, I am finding that if I output as jpg file, I get other values in there as well. If I output as gif, I also get other values in there too. I am sure I am doing something stupid as there must be a way to do this. My test file is this attached jpg greyscale file. Is there a way to process this test file so that only 0 or 255 appears in the output image please? Thanks. Here is my program <?php $url = 'greyscale_image.jpg'; $outfile = 'greyscaleout'; $src = imagecreatefromjpeg($url); $w = imagesx($src);$h = imagesy($src); $loband = 80;$hiband = 255; $im_r = imagecreatetruecolor($w,$h); imagefill($im_r,0,0,imagecolorallocate($im_r,255,0,0)); $im_j = imagecreatetruecolor($w,$h); imagefill($im_j,0,0,imagecolorallocate($im_j,255,0,0)); for ($x=0;$x<$w;$x++) { for ($y=0;$y<$h;$y++) { $idx = imagecolorat($src,$x,$y); $rgb = imagecolorsforindex($src,$idx); // this is safest (for gifs) rather than some calculation - apparently $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; $gryout = $r; if ($r <= $loband) { $gryout = 0; // everything less than= loband is black } if ($r > $loband) { $gryout = 255; // everything else is white } if ( ($gryout == 0) || ($gryout == 255) ) { // only zero or 255 allowed $idx = imagecolorallocate($im_r,$gryout,$gryout,$gryout); imagesetpixel($im_r,$x,$y,$idx); // imagesetpixel($im_j,$x,$y,$idx); // $idx2 = imagecolorat($im_r,$x,$y);// if ($idx != $idx2) { die($idx2." at x,y ".$x.",".$y); } $rgb = imagecolorsforindex($im_r,$idx); // this is safest (for gifs) rather than some calculation - apparently $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; if ($r != 0) { if ($r != 255) { die($r." at x,y ".$x.",".$y); } } } else { die('<br>Grey going out to image is '.$gryout); } } } imagegif($im_r,$outfile.'.gif');imagedestroy($im_r); imagejpeg($im_j,$outfile.'.jpg');imagedestroy($im_j); // ========================== // done the writing, now check it // ========================== // $outfile = 'greyscale_image'; // test using original $src = imagecreatefromjpeg($outfile.'.jpg'); $w = imagesx($src);$h = imagesy($src); $errcount = 0; $x = 0; while($x<$w) { $y = 0; while($y<$h) { $idx = imagecolorat($src,$x,$y);// $rgb = imagecolorsforindex($src,$idx); // this is safest (for gifs) rather than some calculation $r =$rgb['red']; $g = $rgb['green']; $b = $rgb['blue']; if ($r != 0) { if ($r != 255) { echo sprintf('<br>r(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($g != 0) { if ($g != 255) { echo sprintf('<br>g(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($b != 0) { if ($b != 255) { echo sprintf('<br>b(%d,%d) r=%d g=%d b=%d',$x,$y,$r,$g,$b);$errcount++; } } if ($errcount > 10) {break 2;} $y++; } $x++; } if ($errcount == 0) {die( ' Checked OK' );} die( ' Checked NOT OK' ); // ================= ?> Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Code: [Select] <?php $query = "Select * from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $test = $_POST['test1']; $ques = "Select * from questions where testname = '$test' "; $qres = mysql_query($ques) or die(mysql_error()); $qdetails = mysql_fetch_array($qres); $id = $qdetails['id']; $testname = $qdetails['testname']; $ans = "Select * from answers where qid = $id"; $ares = mysql_query($ans) or die(mysql_error()); if($qdetails) { ?> <div class="padding"> <form name="answerform" action="answer.php" method="POST"> <h3> </h3> <input name="test2" id="test2" type="text" value="<?php echo $qdetails['testname'];?>" /><h3><?php echo $qdetails['text'];?></h3> <input name="test3" id="test3" type="text" value="<?php echo $qdetails['testseries'];?>" /><h3><?php echo $qdetails['text'];?></h3> <br /> <br /> <br /> <?php while($opdetails = mysql_fetch_assoc($ares)) { ?> <input class="text" id="opt2" name="correctans" type="radio" value="<?php echo $opdetails['text']; ?>" /><br /><?php echo $opdetails['text']; ?> <?php }?> <div class="two-fields clearfix". <p class="confirm"> </p> </div> <input type="submit" value="SUBMIT ANSWER" /> </form> </div> </div> </div> <?php } this is the code for the program where i am creating the fields i want to fetch the data from the input fields with the name test 2 and test 3 in answer.php Code: [Select] $query = "Select score from users where username = '$user' "; $result = mysql_query($query) or die(mysql_error()); $row = mysql_fetch_array($result); $user_score = $row['score']; print_r($_REQUEST); $tester = $_POST['test3']; $test = $_POST['test2']; print_r($_POST); var_dump($_POST); $ques = "Select * from questions where testname = '$test' And testseries = '$tester' "; $result = mysql_query($ques) or die(mysql_error()); $row = mysql_fetch_array($result); $qid = $row['id']; $score = $row['score']; if(isset($_POST['correctans'])) { $answer = $_POST['correctans']; } else { $answer = ''; } $fetch_ans = "Select * from answers where correct = 1 AND qid = $qid"; $result = mysql_query($fetch_ans) or die(mysql_error()); $row = mysql_fetch_array($result); $id = $row['id']; $correctans = $row['text']; if('$correctans' == '$answer') { $user_score += $score; $qid++; $query = "Update users set score = $user_score where username = '$user'"; $res = mysql_query($query) or die(mysql_error()); if($res) { header("Location: answer.php"); } }else { header("Location: answer.php"); } ?> THIS IS answer.php and here i try to post information from test2 and test3 fields but i am not getting any output the output shows blank array() and unidentified index test2 and unidentified index test3 i am not able to figure out the error any help will be highly appreciated and forgive me if i have made any mistakes in posting the question since i am a newbie at PHPFREAKS Hi! This bit of code does exactly what I want it to just not sure why. The way I would (***_u_me) this code to be written would be to replace the echo ($array_2[$index]); with echo ($array_2[$value]); to get the output I'm getting. Basically the foreach loop loops through $array_1 when it finds a key with a null value it outputs the $value or the $index which ever I decide to output of $array_2 which corresponds to that value. when I echo ($array_2[$value]) I get no output and when I echo ($array_2[$index]) I get the wanted output below. It doesn't seem right <?php function test() { $array_1 = array("Matt" => NULL, "Kim" => 1, "Jessica" => NULL, "Keri" => 1); $array_2 = array("Matt","Kim","Jessica","Keri"); foreach ($array_2 as $index => $value) { if (!isset($array_1[$value])) { echo ($array_2[$index]); echo "<br />"; } } } test(); ?> output Matt Jessica Thanks, steadythecourse This is kind of weird, I've tried to figure out what is wrong for a while now, but I really can't seem to figure it out. My script does seem to work with the values I think it works with, but that might be where the error is. I've messed around a lot with it, but I still can't seem to understand what the problem is... I do realize I can just use the filledrectangle function instead of creating a new image for each background color, but the problem itself really annoys me. The black line doesn't appear anywhere but between the two first background colors and only if both background colors are visible... o.O Might be I need to use some other imagecopy function, but this is all so weird! <?php // image size $x=500; $y=100; // creating transparent image $im=imagecreatetruecolor($x,$y); $tc=imagecolorallocatealpha($im,255,255,255,0); imagefill($im,0,0,$tc); // background colors // the escaped lines is for making a background image transparent, to see where the black line appears $bgc[]=array(255,0,0,0); //$bgc[0]=array(255,0,0,127); $bgc[]=array(0,255,0,0); //$bgc[1]=array(0,255,0,127); $bgc[]=array(0,0,255,0); $bgc[]=array(0,255,255,0); // adding backgrounds // background count: $bgcq=count($bgc); // backgroundsize x,y: $bgs=array(ceil($x),($y+1)/$bgcq); // location: $bgsl=0; // last height: $bgsh=0; for($i=0;$i<$bgcq;$i++){ // start location for this background: $bgsl+=$bgsh; // calculating a round number for the background height if($bgsl+$bgs[1]<round($bgs[1]+($bgs[1]*$i))){ $bgsh=ceil($bgs[1]); }else{ $bgsh=floor($bgs[1]); } // creating background image: $bg=imagecreatetruecolor($bgs[0],$bgsh); // filling background image with set color $abgc=imagecolorallocatealpha($bg,$bgc[$i][0],$bgc[$i][1],$bgc[$i][2],$bgc[$i][3]); imagefill($bg,0,0,$abgc); // pasting background on image (imagecopy gives the same result) imagecopyresampled($im,$bg,0,$bgsl,0,0,$bgs[0],$bgsh,$bgs[0],$bgsh); // to see the values (test purpose), must escape header and imagepng functions //echo $bgsl.'-'.($bgsl+$bgsh).'<br />'.$bgsh.'<br />'; } // output, remember to escape it to echo variables header('Content-type: image/png'); imagepng($im,NULL,0); ?> I've tried to make the script as understandable and easy as possible... anyone got any ideas about what is wrong here, and how to maybe fix it? base64_encode is a perfect standard php encoding, but this produces = most of times. Is there an alternative making the encode by alphanumeric only? Hello There, I have been trying to get my page going for some time. I have managed to setup my database on mysql. I have managed to create myself a few pages that look how I want and do what I want. I have managed to get the data I want into my database. Where I am struggling big time is to find some way to get the images that I have gotten into my database back out again with a php page. I have managed to do a dynamic drop down, from one of the tables, but when I bring back the image files I get the binary, or a readout of the file. (I have a .gpx file as well as a load of .jpg files). The code I have managed so far is below, does anyone feel inclined to help me get a little further with this? I am new to HTML and to PHP, although databases are perhaps a little more familiar to me. I would like if possible to show the images in the lower half of the same page that the drop down is on, although if this is not possible then please let me know. <?php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("unable to connect to MySQL: " . mysql_error()); //connecting to the database. mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); // If submitted, check the value of "select". If its not blank value, get the value and put it into $select. if(isset($select)&&$select!=""){ $select=$_GET['select']; } ?> <body> <form method="POST" action="predroptest.php"> Hills : <select name="selecthill"> <option value="">--- Select Hill---</option> <? // Get records from database (table "Hills"). $list=mysql_query("select ID, Hill from Hills order by Hill"); // Show records by while loop. while($row_list=mysql_fetch_assoc($list)){ ?> <option value="<? echo $row_list['ID']; ?>" <? if($row_list['ID']==$select){ echo "selected"; } ?>><? echo $row_list['Hill']; ?></option> <? // End while loop. } ?> </select> <input type="submit" name="Submit" value="Select" /> </form> <hr> <p> <? // Get records from database (table "Hills"). $select1=$_POST['selecthill']; $query="SELECT * FROM Objects Where Data_ID='$select1'"; $result=mysql_query($query); $num=mysql_numrows($result); echo "<b><center>Hill Info</center></b><br><br>"; $i=0; while ($i < $num) { $Data_ID=mysql_result($result,$i,"Data_ID"); $Object=mysql_result($result,$i,"Object"); $Type=mysql_result($result,$i,"Type"); $Description=mysql_result($result,$i,"Description"); header('Content-type: image/jpg'); echo "<b>$Data_ID<br>$Object<br>$Type<br>$Description<hr><br>"; $i++; } mysql_close(); ?> </p> </body> Thanks very much for the help Diana Tracy www.up-a-hill.me.uk Hello all, I have yet again trouble finding a logical solution to my problem. I'm fetching an array which can hold 1 or more values. The problem is, I want these values to ouput in my json_encode function, but this also needs to happen dynamically depending on the amount of values. I can't explain it further, so here's the code so far: Code: (php) [Select] $files = mysql_fetch_array($get_files); $a = count($files); $i = 1; while ($files) { $variablename = 'fileName' . $i; $$variablename = $files['fileName']; $i++; } $output = array( OTHER VALUES , 'fileName1' => $fileName1, 'fileName2' => $fileName2, 'fileName3' => $fileName3, ............); // How do I add the fileNames dynamically depending on how many there are? This got me thinking, I also need to dynamically GET the values with jQuery. How would I do that, when the above eventually works? Thank you. I've used this before and it worked fine but the mt_rand is not working properly. It keeps producing the same number. I've tested it on with the $_GET to the next page and it produces a unique code but it doesn't want to insert that number into the table, just the other same, repetitive number. $transaction_id = mt_rand() . mt_rand(); $item_email = mysql_real_escape_string($_POST[email]); $item_first_name = mysql_real_escape_string($_POST[first_name]); $item_last_name = mysql_real_escape_string($_POST[last_name]); $item_street = mysql_real_escape_string($_POST[street]); $item_street2 = mysql_real_escape_string($_POST[street_2]); $item_city = mysql_real_escape_string($_POST[city]); $item_state = mysql_real_escape_string($_POST[state]); $item_zip_code = mysql_real_escape_string($_POST[zip_code]); $item_country = mysql_real_escape_string($_POST[country]); $username = $_SESSION['username']; $item_id = $_GET['id']; $item_title = mysql_real_escape_string($_POST[title]); $item_price = mysql_real_escape_string($_POST[price]); $item_shipping_cost = mysql_real_escape_string($_POST[shipping_cost]); $item_in_shipping = mysql_real_escape_string($_POST[in_shipping]); $okay = TRUE; if ($item_country == 'United States'){ $shipping = "$item_shipping_cost"; } else { $shipping = "$item_in_shipping - <span class=\"submissionfont\">International Rate</span>"; } $sql="INSERT INTO buyer (username, email, first_name, last_name, street, street_2, city, state, zip_code, country, transaction_id, date) VALUES ('$username', '$item_email', '$item_first_name', '$item_last_name', '$item_street', '$item_street2', '$item_city', '$item_state', '$item_zip_code', '$item_country', '$transaction_id', CURDATE())"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } $sql2="UPDATE product SET transaction_id='$transaction_id', sold='1', sold_date=CURDATE() WHERE id = '$item_id'"; if (!mysql_query($sql2)) { die('Error: ' . mysql_error()); } I am trying to join two tables but I am producing no results. I'm convinced that I have entered everything correctly, but clearly I haven't? Can anyone spot my mistake?
<?php require 'core/memberinit.php'; $member = new Member(); include 'timeago.php'; $memberid = $member->data() ->id; if(isset($_GET['q'])) { $q = html_entity_decode($_GET['q']); $query2 = DB::getInstance()->query("SELECT c.id c.time as time, c.message as message, c.removed1, c.removed2, m1.member_first_name as firstname1, m1.member_last_name as lastname1, m1.username as username1, m2.member_first_name as firstname2, m2.member_last_name as lastname2, m2.username as username2 FROM conversation c LEFT JOIN members m1 ON c.member1=m1.id LEFT JOIN members m2 ON c.member2=m2.id WHERE (c.id=$q OR c.originalid=$q) AND ((c.member1=$memberid AND c.removed1='No') OR (c.member2=$memberid AND c.removed2='No')) ORDER BY c.id"); foreach ($query2->results() as $result2) { echo $result2->firstname1; echo $result2->lastname1; echo $result2->username1; echo timeAgo(strtotime($result2->time)); echo $result2->message; echo $result2->firstname2; echo $result2->lastname2; echo $result2->username2; } ?> Edited by MartynLearnsPHP, 23 November 2014 - 12:55 PM. How can I resize an image that i'm showing and rather than saving it, just output the file? And would this vary if I was to be first calling the image through AJAX? Hi, I have an image (a weather map) which is created using php which pulls data from a mysql database. I would like to be able to output the result image as a gif or jpg file. Can anyone suggest how this could be done? Many thanks, Simon sure, I know how to output a picture with a php script. the problem is, the host I use, they won't let me edit the php.ini file to look through png files for PHP scripts before outputting. Of course, it is bad practice anyways... Is there any way to make it easy for a user to download the image with a .png extension instead of .php. (I know this is done automatically in windows 7, like: image.php.png because it reads the content type). Any good ideas? =) hello, when i add Code: [Select] echo $row['img']; to the code below it prevents it from working correctly. Have I written the line correctly or is there another underlying cause? any help greatly appreciated. working = http://www.1pw.co.uk/demo2.php not working = http://www.1pw.co.uk/demo.php Code: [Select] <?php define('INCLUDE_CHECK',1); require "../#########.php"; if(!$_POST['img']) die("There is no such product!"); $img=mysql_real_escape_string(end(explode('/',$_POST['img']))); $row=mysql_fetch_assoc(mysql_query("SELECT * FROM internet_shop WHERE img='".$img."'")); echo $row['img']; echo '{status:1,id:'.$row['id'].',price:'.$row['price'].',txt:\'\ \ <table width="100%" id="table_'.$row['id'].'">\ <tr>\ <td width="60%">'.$row['name'].'</td>\ <td width="10%">$'.$row['price'].'</td>\ <td width="15%"><select name="'.$row['id'].'_cnt" id="'.$row['id'].'_cnt" onchange="change('.$row['id'].');">\ <option value="1">1</option>\ <option value="2">2</option>\ <option value="3">3</option></slect>\ \ </td>\ <td width="15%"><a href="#" onclick="remove('.$row['id'].');return false;" class="remove">remove</a></td>\ </tr>\ </table>\'}'; ?> not sure if needed but this is the file that includes the above file.... Code: [Select] var purchased=new Array(); var totalprice=0; $(document).ready(function(){ $('.product').simpletip({ offset:[40,0], content:'<img src="img/ajax_load.gif" alt="loading" style="margin:10px;" />', onShow: function(){ var param = this.getParent().find('img').attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = this.getParent().find('img').attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } this.load('ajax/tips.php',{img:param}); } }); $(".product img").draggable({ containment: 'document', opacity: 0.6, revert: 'invalid', helper: 'clone', zIndex: 100 }); $("div.content.drop-here").droppable({ drop: function(e, ui) { var param = $(ui.draggable).attr('src'); if($.browser.msie && $.browser.version=='6.0') { param = $(ui.draggable).attr('style').match(/src=\"([^\"]+)\"/); param = param[1]; } addlist(param); } }); }); function addlist(param) { $.ajax({ type: "POST", url: "ajax/addtocart.php", data: 'img='+encodeURIComponent(param), dataType: 'json', beforeSend: function(x){$('#ajax-loader').css('visibility','visible');}, success: function(msg){ $('#ajax-loader').css('visibility','hidden'); if(parseInt(msg.status)!=1) { return false; } else { var check=false; var cnt = false; for(var i=0; i<purchased.length;i++) { if(purchased[i].id==msg.id) { check=true; cnt=purchased[i].cnt; break; } } if(!cnt) $('#item-list').append(msg.txt); if(!check) { purchased.push({id:msg.id,cnt:1,price:msg.price}); } else { if(cnt>=3) return false; purchased[i].cnt++; $('#'+msg.id+'_cnt').val(purchased[i].cnt); } totalprice+=msg.price; update_total(); } $('.tooltip').hide(); } }); } function findpos(id) { for(var i=0; i<purchased.length;i++) { if(purchased[i].id==id) return i; } return false; } function remove(id) { var i=findpos(id); totalprice-=purchased[i].price*purchased[i].cnt; purchased[i].cnt = 0; $('#table_'+id).remove(); update_total(); } function change(id) { var i=findpos(id); totalprice+=(parseInt($('#'+id+'_cnt').val())-purchased[i].cnt)*purchased[i].price; purchased[i].cnt=parseInt($('#'+id+'_cnt').val()); update_total(); } function update_total() { if(totalprice) { $('#total').html('total: $'+totalprice); $('a.button').css('display','block'); } else { $('#total').html(''); $('a.button').hide(); } } not sure if this is needed, but it links to the above file; Code: [Select] <?php define('INCLUDE_CHECK',1); require "######.php"; ?> <!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>shop</title> <link rel="stylesheet" type="text/css" href="demo.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script> <script type="text/javascript" src="jquery.ui.main.js"></script> <!--[if lt IE 7]> <style type="text/css"> .pngfix { behavior: url(pngfix/iepngfix.htc);} .tooltip{width:200px;}; </style> <![endif]--> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js"></script> <script type="text/javascript" src="simpletip/jquery.simpletip-1.3.1.pack.js"></script> <script type="text/javascript" src="script.js"></script> </head> <body> <div id="main-container"> <div class="tutorialzine"> <h1>Shopping cart</h1> <h3>The best products at the best prices</h3> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Products</span> </span> <div class="content-area"> <div class="content drag-desired"> <?php $result = mysql_query("SELECT * FROM internet_shop"); while($row=mysql_fetch_assoc($result)) { echo '<div class="product"><a href="#" class="item"><img src="img/products/'.$row['img'].'" alt="'.htmlspecialchars($row['name']).'" width="128" height="128" class="pngfix" /></a></div>'; } ?> <div class="clear"></div> </div> </div> <div class="bottom-container-border"> </div> </div> <div class="container"> <span class="top-label"> <span class="label-txt">Shopping Cart</span> </span> <div class="content-area"> <div class="content drop-here"> <div id="cart-icon"> <img src="img/Shoppingcart_128x128.png" alt="shopping cart" class="pngfix" width="128" height="128" /> <img src="img/ajax_load_2.gif" alt="loading.." id="ajax-loader" width="16" height="16" /> </div> <form name="checkoutForm" method="post" action="order.php"> <div id="item-list"> </div> </form> <div class="clear"></div> <div id="total"></div> <div class="clear"></div> <a href="" onclick="document.forms.checkoutForm.submit(); return false;" class="button">Checkout</a> </div> </div> <div class="bottom-container-border"> </div> </div> </div> <div class="bowlpic"> </div> </body> </html> Well I have a script that executes a scan on a system set to run infinitely, and I need it to echo out a message each time it loops through, but I don't want it to echo out the message with the next loop message below it, and the next one below that etc... I've tried using the flush(); function and been messing around with that with no luck. For security reasons I don't want to release any of the processing code, but here is the basic construction of the script: <?PHP ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $RepeatIt = -1; for($g=1; $g!=$RepeatIt+1; $g++) { ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** $ScanMessage = ":.:.: SCANNING THE HITLIST FOR MOBSTER: ".$MobName." (SCAN #$g) :.:.:"."<br/><br/>"; echo $ScanMessage; ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** ***PROCESSING AND SCAN CODE*** } ?> At the moment it's returning: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #1) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #2) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #3) :.:.: :.:.: SCANNING THE HITLIST FOR MOBSTER: DEUS EX DESTROYER (SCAN #4) :.:.: So what I want it to do is just delete the scanning message and replace it with the next scan message so while running this script you would see just the number increment on the same line. Any suggestions? Thanks. I have written code so that when something from a MySQL field equals 0, then PHP will take no action, and if the field equals anything else, then 'echo "foo"'. The problem I am having is that when PHP echo's nothing (echo ""), its still creating the effect of a HTML <BR>. Screen shots: 1. When the MySQL table contains something else than 0 (echo "foo"). http://i51.tinypic.com/2n7oxo1.png 2. When the table contains 0 (echo ""). http://i53.tinypic.com/2h5jg4k.png 3. What it should look like if the table were to contain 0 (echo ""). Note that their is no <BR> effect. http://i51.tinypic.com/2jdtaf.png Code: $query = "select sizes from products where id='$id'"; $result = mysql_query($query); $data = mysql_fetch_array($result); if ($data['sizes'] == 0) {echo "";} else {echo "Small - ".$data['sizes'];} Is it possible to make it so if a MySQL field result equals 0, then PHP will not produce the HTML <BR> effect when it echo's nothing (echo "")? Hello again, guys! I have a couple of questions that I hope anyone can answer. I am making a form that is storing the information in a database, and in this form I also want images to be uploaded. I want to make a function that allows the user to upload as many images as they would like to have in their ad on my website, and I also need something that can handle the upload process, and see how many images the user is trying to upload. Any easy solutions for this? I also have another question: As you can see on the example image underneath this text, I have a form with multiple inputs where the user is suppose to choose how many inputs they want to fill in themself. How should I store this information in the database, and how can I make a script that detects how many of the forms the user actually filled? I hope you guys understood what I was trying to say, and I thank you all anyways. Underneath you can see an image of my forms. Example image: Cheers, Marius Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabuHi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) |